System Design HLD-08.03
PACELC and consistency models
PACELC adds the everyday latency versus consistency trade-off to CAP; then the spectrum from linearizable through sequential and causal to eventual consistency.
The big idea
CAP only describes what happens during a partition, which is rare. Most of the time the network is fine, yet replicated systems still face a trade-off on every request: to guarantee a read sees the latest write, replicas must coordinate, which takes round trips, which takes time. PACELCIf there is a Partition, choose Availability or Consistency; Else, in normal operation, choose Latency or Consistency. captures both situations in one line: if Partition, choose Availability or Consistency; Else, choose Latency or Consistency.
"Consistency" is also not one thing. Between "behaves exactly like a single copy" and "copies agree eventually, someday" lies a spectrum of consistency modelsA contract describing which values reads may return given the order of writes, from strict (linearizable) to loose (eventual)., each a different promise about what reads may return. Stronger promises are easier to program against; weaker ones are faster, more available and scale further. Picking the weakest model your feature can tolerate is one of the most valuable design skills.
Think of news. A live phone call with a reporter is strongly consistent but slow and expensive. A daily newspaper is eventually consistent: cheap, fast to read, slightly out of date, and everyone sees events in a sensible order.
How it works
Step 1: PACELC classification
- PA/EL: during a partition favor availability, otherwise favor latency. Dynamo-style stores such as Cassandra by default: fast and always on, eventually consistent.
- PC/EC: favor consistency in both cases. Consensus-based systems and distributed SQL such as Spanner or CockroachDB: every write coordinates with a majority, so writes cost at least one round trip to a quorum, across regions if replicas are global.
- PA/EC and PC/EL exist too, and many systems let you choose per request, for example a quorum read versus a single-replica read.
Step 2: The spectrum
- Linearizable: every operation appears to happen at one instant between its start and end; once a write completes, all later reads see it. Needed for locks, leader election, unique usernames.
- Sequential: all clients see all operations in the same single order, consistent with each client's own order, but that order may lag real time.
- Causal: operations that are causally related (a reply and the message it answers) are seen in that order by everyone; unrelated concurrent operations may be seen in different orders. It is the strongest model that remains available during partitions, which makes it attractive for collaborative and social apps.
- Eventual: if writes stop, replicas converge to the same value. No promise about what you read in the meantime.
The session guarantees from Replication lag and read consistency guarantees (read-your-writes, monotonic reads) are useful slices of this spectrum that cost little.
Try it
Going deeper
Why stronger costs latency
A linearizable write must be acknowledged by a majority before it completes, and a linearizable read must either go through the leader with a lease or contact a majority. If replicas are in different regions, that is a cross-region round trip on every operation, tens to hundreds of milliseconds. Spanner reduces read costs with synchronized clocks ( Time and clocks ), but writes still pay the quorum round trip.
Trade-offs
| Option | Wins when | Loses when |
|---|---|---|
| Linearizable | Locks, elections, uniqueness, money: correctness above all | Latency on every operation and availability during partitions |
| Causal | Social and collaborative features that need sensible ordering while staying available | Global uniqueness guarantees; more metadata to track |
| Eventual | Counters, feeds, caches, DNS: maximum speed and availability | Any guarantee about what reads return in the meantime |
Common mistakes
- Using linearizable storage for everything and paying cross-region latency on every like.
- Using eventual consistency for uniqueness constraints and getting duplicate usernames.
- Assuming "strongly consistent" in vendor docs means linearizable; read the exact guarantee.
- Forgetting that caches in front of a strong database make reads eventually consistent.
Check yourself
-
What does the 'ELC' in PACELC describe?
Show answer
B. The latency versus consistency trade-off in normal operation Else (no partition), choose Latency or Consistency.
-
Which model is required to guarantee a username is unique?
Show answer
C. Linearizable All clients must agree on a single order of the competing sign-ups.
-
What does causal consistency guarantee?
Show answer
B. Causally related operations are seen in order by everyone Effects never appear before their causes; unrelated operations may be seen in different orders.
-
Why do linearizable writes cost more latency?
Show answer
B. They must be acknowledged by a quorum before completing Coordination with a majority adds at least one round trip, possibly across regions.
Recap
- PACELC: during a partition choose A or C; otherwise choose latency or consistency.
- Consistency models range from linearizable through sequential and causal to eventual.
- Stronger models are easier to reason about; weaker ones are faster and more available.
- Causal consistency is the strongest model that stays available during partitions.
- Pick the weakest model each feature can tolerate.