Part 5 · 2 chapters · ~16 min

Consistency Models

The consistency ladder: linearizable with a timeline picture, sequential, causal and eventual, and choosing per operation with the defaults and options of real stores; then CAP as behaviour during a partition and PACELC as the latency trade the rest of the time.

10

Linearizable, sequential, causal, eventual

a contract about what reads may return
  1. Linearizable: behaves like one copy, in real time.
  2. In a picture: once anyone has seen the new value, nobody sees the old one.
  3. Sequential: everyone agrees on one order, though not necessarily in real time.
  4. Causal: causes are seen before their effects. It is the strongest model that stays available during a partition.
  5. Eventual: replicas converge once writes stop. Nothing is promised before that.
  6. Choose per operation and pay for strength only where an anomaly would be a bug.
storedefaultstronger option
Postgres (single primary)linearizable on the primary; replicas lagread from the primary, or wait for the LSN
DynamoDBeventually consistent readsConsistentRead: true (same region), transactions
Cassandraper query: ONE, QUORUM, ALL…QUORUM writes + QUORUM reads; LWT (Paxos) for compare-and-set
Cosmos DBsessionbounded staleness, strong
S3strong read-after-write (since 2020)conditional writes (If-Match / If-None-Match)
Spanner, CockroachDBserializable, linearizablestale reads available for lower latency
THE CONSISTENCY LADDER
linearizable, sequential, causal and eventual: what each promises about the reads you can observe
swipe the figure sideways, or tap expand for full screen
1/6
linearizable
Linearizable: the system behaves as if there is one copy and every operation takes effect atomically at some instant between its start and end. Once a write completes, every later read (by anyone, anywhere) sees it or something newer. This is what people mean by "strongly consistent"; it is what a lock, a leader election or an account balance check needs.
11

CAP and PACELC

what a partition forces, and what latency costs
  1. The setup: replicas in two places.
  2. A partition is not optional. Sooner or later one happens.
  3. CP: refuse requests where there is no quorum. Nothing stale, nothing conflicting.
  4. AP: keep serving on both sides and reconcile later.
  5. PACELC: the rest of the time, the trade is latency against consistency.
  6. In practice: money is CP, feeds are AP, and many stores let you tune per operation.
the misreading
"CAP means pick two" suggests you could build a CA system. On a real network there is no such thing, because partitions happen. What you choose is behaviour during a partition (refuse or diverge), and behaviour the rest of the time (wait or answer fast). A system that never says which has made the choice anyway, by accident.
CAP AND PACELC
what a network partition forces you to give up, and the latency trade that applies the rest of the time
swipe the figure sideways, or tap expand for full screen
1/6
the setup
The setup: two replicas, one in Lagos and one in London, both serving reads and writes of an account's balance. Normally they replicate to each other and agree.