Topic 129 / Core
Consistency models: linearizability, sequential, causal, eventual; read-your-writes, monotonic reads, consistent prefix, stale reads
Chapter 8.2 · Consistency Theory
What and why
Topic 128 showed consistency is a per-data-item choice between extremes; this topic gives the vocabulary for everything in between. A consistency model is a precise guarantee about what order and recency of writes a reader is promised to see. From strongest to weakest: linearizability (every read sees the most recent write, as if there were one copy of the data), sequential consistency (all nodes see all operations in the same order, though not necessarily real-time order), causal consistency (causally related operations are seen in that order everywhere; unrelated operations may be seen in different orders), and eventual consistency (replicas converge to the same value only if writes stop). Layered on top, the session guarantees make eventual consistency livable: read-your-writes (a client always sees its own prior writes), monotonic reads (a client never sees an older value after a newer one), and consistent prefix (a client never sees an effect before its cause). A stale read is any read older than the current value. Builds on: → 128 (CAP theorem and PACELC).
Diagram
| Model | Guarantee | Coordination cost |
|---|---|---|
| Linearizability | looks like one copy, always current | highest |
| Sequential | same order everywhere, not necessarily real-time | lower |
| Causal | causally related ops ordered; unrelated may differ | lower still |
| Eventual (+ session guarantees) | converges only if writes stop; read-your-writes / monotonic reads / consistent prefix add specific promises on top | lowest |
How it works
- Pick the model per data item (→ 128): ask what a stale or out-of-order read would actually cost in that specific case.
- Linearizability needs coordination on every read and write (quorums → 130, or a single leader) — most expensive, easiest to reason about.
- Causal consistency tracks "happens-before" (→ 134) and orders only what's actually linked, letting unrelated writes stay cheap and concurrent.
- Eventual consistency alone makes no promise about when convergence happens or what a reader sees before it — which is why production systems almost always add at least one session guarantee on top.
- Read-your-writes is typically implemented by routing a client's own reads to wherever its last write landed for a bounded window; monotonic reads by always reading from the same replica, or one no older than one already seen; consistent prefix by preserving write order within a replication stream.
Practical example
(illustrative). A user posts a comment (write A), then reloads the page (read B). Under plain eventual consistency, B might be routed to a replica that hasn't received A yet — the user doesn't see their own comment. Adding read-your-writes (route B to the replica holding A, or to the leader, for the next few seconds) fixes this one visible symptom without paying for full linearizability on every other read on the page.
When to use it
- Use when: linearizability for data where any staleness is a correctness bug (a unique seat hold, a payment status); causal or eventual plus read-your-writes for most user-facing content (posts, comments) where a few seconds of staleness is invisible.
- Avoid when: labeling a system "eventually consistent" without naming which session guarantees it actually provides — plain eventual consistency permits a reader to go backward in time.
- Failure scenarios: a comment that disappears and reappears because monotonic reads wasn't provided; a reply visible before the comment it replies to because consistent prefix wasn't preserved; an "eventually consistent" counter read as a live value on a dashboard.
- Simpler alternative: a single-node or single-leader system gets linearizability for free — don't adopt weaker models until replication (→ 72) actually forces the trade-off.
Practice
(Vocabulary kind — classification drills; 20–30 min, no lab services). For 6 scenarios (a user edits their profile, then immediately views it; two unrelated users post at the same time and see each other's posts in different order; a feed shows a reply before the original post; a replica serves a value, then on the next request from the same client serves an older one; and two more of your own), name which guarantee is violated (linearizability, causal order, read-your-writes, monotonic reads, or consistent prefix) and which guarantee, added, would fix it. Done when every scenario is matched to exactly one violated guarantee with a one-line justification.
Key takeaway
Consistency is a ladder from linearizable to eventual, and the session guarantees are what make a point below the top of that ladder usable in practice. Done when you can: name the weakest model that still prevents a stated user-visible bug. Used next in → 130, 131, 134; Project 7.
References
Kleppmann and Riccomini, Designing Data-Intensive Applications — see
references.md.