Distributed Systems for Backend Engineers · Distributed Systems Fundamentals

Consistency Models

Linearizability, sequential, causal, read-your-writes and eventual consistency.

A consistency model is a contract about what reads may return. Linearizable (strong): operations appear to happen atomically at one point between call and return — like a single copy. Sequential: one global order, not necessarily real-time. Causal: causally related operations are seen in order by everyone. Session guarantees (read-your-writes, monotonic reads) are practical middle grounds. Eventual: replicas converge if writes stop. Stronger models cost latency and availability.

Consistency spectrum

Model Guarantee Cost Example systems
Linearizable Real-time single-copy behavior Highest latency; unavailable in partitions etcd, ZooKeeper, Spanner
Sequential Single global order High Some replicated logs
Causal Cause before effect everywhere Medium MongoDB causal sessions, COPS
Read-your-writes You see your own writes Low Session stickiness, version tokens
Eventual Converges eventually Lowest DNS, Dynamo-style stores, caches
Anomaly under eventual consistency (read from replicas):
t1 user updates profile photo → primary
t2 user refreshes → replica (lagging) → old photo  ✗ read-your-writes violated
Fix: route this user's reads to primary for N seconds, or pass a version token and read from a replica that has caught up.

Common pitfalls

  • Assuming read replicas are strongly consistent.
  • Paying for linearizability everywhere.
  • Not documenting which guarantee each API provides.

Key points

  • Strong ↔ eventual spectrum
  • Session guarantees are practical
  • Choose per use case

Further reading: Jepsen: Consistency models

Practice questions

What's the difference between linearizability and serializability?

Answer

Linearizability is a recency guarantee on single objects (operations appear instantaneous in real time); serializability is a transaction isolation guarantee (transactions appear to run in some serial order). Strict serializability combines both.

How can you give users read-your-writes with read replicas?

Answer

Route a user's reads to the primary briefly after they write, or include a write position/version token and read only from replicas that have replicated past it.

Open in the app to mark lessons complete, take notes and track your progress.