Module 6 - Distributed Systems

Consistency Models

From strong to eventual: understanding data consistency guarantees.

1The Scoreboard Analogy

Simple Analogy
Imagine scoreboards in a stadium:

Strong Consistency: All scoreboards update simultaneously. Everyone sees the same score.

Eventual Consistency: Scoreboards update at different times. You might see 2-1 while your friend sees 2-0, but eventually all show 2-1.

2Consistency Spectrum

1

Strong (Linearizable)

All operations appear atomic and in a single order. As if there's one copy of data.

Latency: HighestExample: Google Spanner, CockroachDB
2

Sequential

Operations from each client appear in order, but different clients may see different orderings.

Latency: HighExample: Zookeeper
3

Causal

Causally related operations are seen in order. Concurrent operations may be seen in any order.

Latency: MediumExample: MongoDB causal sessions
4

Eventual

Given enough time without updates, all replicas converge to the same value.

Latency: LowestExample: DynamoDB, Cassandra

3Real-World Dry Run

Scenario: Social Media Post Visibility

Alice posts "Hello World" at 10:00:00. Bob and Carol read the feed.

Strong

~100-200ms

Bob and Carol both see the post immediately after 10:00:00. No one sees stale data.

Eventual

Variable (seconds)

Bob sees post at 10:00:02, Carol sees it at 10:00:05. Both eventually see it.

Read-Your-Writes

Fast for author

Alice sees her post immediately. Bob might not see it for a few seconds.

4Read-After-Write Variants

Read-Your-Writes

You always see your own writes immediately.

Use case: User profile updates

Monotonic Reads

Once you see a value, you never see an older value.

Use case: Viewing transaction history

Monotonic Writes

Your writes are applied in the order you issued them.

Use case: Editing a document

Writes-Follow-Reads

If you read X then write Y, Y is visible after X.

Use case: Reply to a comment

5Choosing a Model

Bank Account BalanceStrong

Users must always see accurate balance. Inconsistency = lost trust.

Social Media LikesEventual

Seeing 999 vs 1000 likes temporarily is acceptable. Speed matters more.

Shopping CartRead-Your-Writes

User must see items they added. Other users' carts don't matter.

Collaborative EditorCausal

Edits should appear in causal order. Concurrent edits can merge.

6Key Takeaways

1Strong consistency: all see same data, highest latency
2Eventual consistency: will converge, lowest latency
3Causal consistency: respects cause-effect ordering
4Most apps use eventual + session guarantees
5Choose based on business requirements, not technical purity

?Quiz

1. User sees their balance as $100, refreshes, sees $95 (older value). Which guarantee is violated?

2. Best consistency model for a real-time multiplayer game?