Consistency Models
Definition
Consistency model
- In plain English
- A consistency model is the promise a system makes about how up to date and in what order reads will see writes.
- Think of it like
- It is like a newspaper's promise about how fresh its news is.
Strong consistency
- In plain English
- Strong consistency means every read sees the latest completed write, as if there were one copy of the data.
- Think of it like
- It is like a single shared whiteboard everyone looks at.
Linearizability
- In plain English
- Linearizability makes operations appear to take place one at a time, with each happening between its start and finish.
- Think of it like
- It is like one clerk handling requests in an order that respects which customers have already finished.
Eventual consistency
- In plain English
- Eventual consistency means copies may differ for a while but will match once updates stop arriving.
- Think of it like
- It is like news spreading through a village until everyone has heard.
Version number
- In plain English
- A version number identifies which revision of a value you are reading, with higher numbers marking later revisions.
- Think of it like
- It is like numbered drafts of a card, so draft twelve comes after draft eleven.
Why it exists
You save a flashcard edit, refresh, and see its old wording. Another read reaches a newer copy and your edit reappears.
Different promises prevent different surprises. In this lesson, strong consistency means linearizability.
The eventual-consistency definition assumes communication recovers and the system resolves competing changes. Waiting cannot repair permanently isolated copies.
How it works
Read-your-writes
- In plain English
- Read-your-writes guarantees that after you change something, your own reads show it — introduced in Module 3's replication lesson.
- Think of it like
- Like seeing your own post immediately after you publish it.
Monotonic reads
- In plain English
- Monotonic reads guarantee you never see older data after you've seen newer data.
- Think of it like
- Like a clock that never jumps backwards.
Causal consistency
- In plain English
- Causal consistency guarantees that if one update depends on another, everyone sees them in that order.
- Think of it like
- Like never seeing a reply before the message it answers.
| Promise | What you can rely on | Typical cost |
|---|---|---|
| Strong | Completed writes precede later reads in one shared operation order | Coordination and possible unavailability |
| Causal | Dependent updates appear in order | Track dependencies; unrelated writes can differ |
| Read-your-writes | Your later reads include your completed writes | Route or wait for your saved version |
| Monotonic reads | Your session does not return to an older version | Track the newest version already seen |
| Eventual | Copies converge after writes stop and repair completes | Readers may see older values meanwhile |
A viewer reads version eight from replica A, then receives older version seven after refreshing against replica B.
- Read from the current leader after writing, provided its read path checks that it still leads.
- Remember the last version seen and wait or reroute if another copy is behind.
- Using one replica helps only while it stays available and does not lose already-observed progress.
- Guarantees for one user’s reads can be combined; they are not a single ladder of stronger and weaker models.
Examples
Keep your edit visible
After an edit, the app routes that learner’s reads to the leader for ten seconds.
An edit saved as version twelve reaches the current leader, and subsequent reads require at least version twelve before showing the card.
Ten seconds is a useful routing policy, not a proof that followers caught up. Afterward, require the saved version or keep routing safely.
The insight
Give users their own changes without relying on a fixed lag estimate.
Stop the score going backwards
A refresh changes the displayed score from 3–2 to an older 2–2.
Viewer remembers: version 8, score 3-2
Replica replies: version 7, score 2-2
Action: wait or reroute; do not replace version 8
Later correction: version 9 may legitimately change the scorePinning the viewer to one healthy, progressing replica can help. Keep the remembered version when changing replicas after a failure.
The insight
Users notice when the app returns to an older version.
Preserve dependent event order
The kitchen receives “Order cancelled” before “Order placed” and later starts baking.
Send all events for one order through the same ordered queue partition. Keep processing sequential for that order, including retries.
This preserves that order’s dependent events, not causal order across every order or service. Ignore duplicate events and reject invalid status changes.
The insight
Related events need ordering through delivery and processing.
Trade-offs
Pros
- Match guarantees to user needs.
- Avoid coordination where old data is acceptable.
Cons
- Weaker models add application work.
- Mixed guarantees take care to explain.
Use when
- Money or inventory requires coordinated decisions.
- User sessions must preserve observed progress.
Avoid when
- Eventual consistency is chosen without examining visible behaviour.
- Replica stickiness is treated as a guarantee through every failure.
Quick check
Takeaways
- Consistency models describe specific promises about reads and update order.
- Read-your-writes and monotonic reads protect a user’s session.
- Keep dependent updates in order and verify versions when switching copies.