In revision.
Crisp5 min readGo deeper →

Consistency models

A spectrum from linearizable (strongest) to eventual (weakest). Pick the weakest model your product can tolerate.

Consistency models are contracts between the database and your code about what reads can return. From strongest to weakest:

  1. Linearizable: every read sees the latest committed write, in real time. Single-copy illusion.
  2. Sequential: all nodes see operations in the same order, but not necessarily real-time order.
  3. Causal: if A happened before B (you saw A then wrote B), every node sees A before B.
  4. Read-your-writes: you see your own writes immediately. Others might not.
  5. Monotonic reads: you never see time go backward.
  6. Eventual: if writes stop, replicas converge. Anything is allowed in the meantime.

Pick the weakest you can tolerate

Strong consistency costs latency and availability. Weak consistency costs developer sanity. The trick is matching the model to the user expectation.

  • Bank balance: linearizable. Showing stale balance after a withdrawal is a bug.
  • Shopping cart: causal or read-your-writes. User must see their own add.
  • Like counter: eventual. Off by a few for 200ms is invisible.
  • News feed ranking: eventual + monotonic. Posts cannot disappear and reappear.

Causal is the sweet spot

Causal consistency is the strongest model you can have while staying available under partition (CAP-wise). It captures the intuitive "happens-before" relationship without paying for global ordering.

Example: you post a status. Friend comments on it. Stranger should never see the comment before the status. Causal consistency guarantees this. Eventual does not.

Most "production-grade" eventually consistent systems add causal session guarantees on top: read-your-writes, monotonic reads, monotonic writes, writes-follow-reads. These four together give per-session causal consistency, which feels strong enough for most apps.

Consistency hierarchy: each is strictly weaker than the one above

Interview answer

"What consistency do you need?" is the right opening question for any system design. "Linearizable everywhere" is almost never the answer because it does not scale. Default to causal session consistency, escalate to linearizable for money and inventory, drop to eventual for counters and analytics.

Learn more