Consistency Models
From strong to eventual: understanding data consistency guarantees.
1The Scoreboard Analogy
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
Strong (Linearizable)
All operations appear atomic and in a single order. As if there's one copy of data.
Sequential
Operations from each client appear in order, but different clients may see different orderings.
Causal
Causally related operations are seen in order. Concurrent operations may be seen in any order.
Eventual
Given enough time without updates, all replicas converge to the same value.
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-200msBob 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 authorAlice 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
Users must always see accurate balance. Inconsistency = lost trust.
Seeing 999 vs 1000 likes temporarily is acceptable. Speed matters more.
User must see items they added. Other users' carts don't matter.
Edits should appear in causal order. Concurrent edits can merge.
6Key Takeaways
?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?