Consistency Models in Distributed Systems
On this page
What a consistency model is
"Strongly consistent" and "eventually consistent" get used loosely. A consistency model is precise: it lists which results a read is allowed to return, given the writes that happened. Stronger models forbid more surprising results and cost more coordination.
Linearizable, sequential, causal and eventual consistency
Linearizability. The system behaves as if there's one copy of each item and every operation happens instantly at some point between its start and end. Once a write completes, every later read, by anyone, sees it or something newer. This is what CAP's "C" means. Consensus systems (etcd, ZooKeeper's sync reads), Spanner and single-leader databases reading from the leader provide it.
Sequential consistency. All operations appear in one order that every node agrees on, consistent with each client's own order, but that order needn't match real time. A read may return a value that's slightly behind, as long as everyone sees the same history.
Causal consistency. Operations related by cause and effect (Day 4) are seen in that order by everyone; unrelated (concurrent) operations may be seen in different orders. A reply is never visible before the comment it answers. It's the strongest model that stays available during partitions.
Eventual consistency. If writes stop, all replicas eventually return the same value. Until then, reads can return old values, and different readers can see different values. Very available and fast; gives no ordering guarantees in the meantime.
The same scenario under each model
Alice changes her profile photo; a moment later Bob reloads her profile.
| Model | Can Bob see the old photo after Alice's update completed? |
|---|---|
| Linearizable | No |
| Sequential | Yes, briefly, but no one sees new then old |
| Causal | Yes, unless Bob's request is causally after Alice's update (for example, he saw her comment about it) |
| Eventual | Yes, and refreshes may flip between old and new until replicas converge |
Session guarantees: read-your-writes and monotonic reads
Between causal and eventual sit practical guarantees for a single client's experience, which fix the most visible anomalies cheaply (Day 12):
- Read-your-writes: you see your own updates.
- Monotonic reads: you never see data go back in time.
- Monotonic writes: your writes are applied in the order you made them.
- Writes-follow-reads: a write based on something you read is ordered after it.
Choosing a consistency model
| Data | Model |
|---|---|
| Unique usernames, balances, locks, leader election | Linearizable |
| Comments and replies, chat messages | Causal |
| User's own profile edits | Read-your-writes on top of eventual |
| Like counts, recommendations, analytics | Eventual |
Pay for strength only where an anomaly would cause real harm; everywhere else, weaker models buy latency and availability (Day 6).
Check yourself
Once a write completes, every later read by anyone sees it or something newer; eventual consistency only promises replicas converge if writes stop.
It guarantees replies are never seen before the messages they answer, while staying available during partitions and avoiding the cost of linearizability.
Read-your-writes. After making a change, a user should always see it in their own later reads. Routing that user's reads to the leader for a short time, or to a replica that's caught up to their write, provides it.
Both give one order all clients agree on. Linearizability also requires that order to respect real time, so a read started after a write completed must see it; sequential consistency doesn't.
Many reads tolerate slightly stale data, such as feeds or counts, and eventual consistency lets replicas answer locally, staying fast and available during failures.