Consistency Models, CAP and PACELC
Understand strong, eventual and causal consistency, what the CAP theorem really says, and how PACELC adds the everyday latency trade-off.
Intermediate · about 3 hours · difficulty 4/5
Learn first: Replication
Once data lives on several machines, you must decide what readers are allowed to see while updates propagate. That decision is your consistency model.
Consistency models, strongest to weakest
- Linearizable (strong): every read sees the latest committed write, as if there were one copy. Needed for bank balances, seat inventory, unique usernames.
- Sequential / causal: everyone sees causally related events in order (a reply never appears before its message).
- Read-your-writes, monotonic reads: session-level guarantees that make apps feel sane.
- Eventual: if writes stop, replicas converge eventually. Fine for like counts, view counts and feeds.
CAP theorem
In a distributed system, when a network Partition happens you must choose between Consistency (refuse or delay requests that cannot see the latest data) and Availability (answer anyway, maybe with stale data). You cannot give up P in a real network, so the real choice is CP vs AP during a partition.
- CP examples: ZooKeeper, etcd, a single-leader SQL database, HBase.
- AP examples: Cassandra and DynamoDB in their default modes, DNS.
PACELC
CAP only talks about failures. PACELC adds: Else (no partition), choose Latency or Consistency. Even on a healthy day, waiting for replicas to agree costs time. Cassandra is PA/EL; a synchronously replicated SQL setup is PC/EC. This framing is closer to what you actually trade daily.
Tunable consistency
Many stores let you choose per request: Cassandra's QUORUM vs ONE, DynamoDB's strongly consistent reads. Use strong reads for money and inventory, eventual reads for everything else.
Pitfalls
- Saying "we pick CA". Without partitions there is no distributed system to discuss.
- Using strong consistency everywhere and paying latency for data nobody needs fresh.
You are ready to move on when you can classify each feature of a ticket booking app as needing strong or eventual consistency and explain the user-visible effect of each choice.
Key concepts
- Strong (linearizable) consistency
- Eventual consistency
- Causal consistency
- CAP theorem
- PACELC
- Tunable consistency
- BASE vs ACID
Mini project
Write a two-page note classifying 12 features of BookMyShow (seat holds, payments, reviews, ratings, recommendations and so on) as CP or AP with reasons, and the database or read mode you would use for each.
Check yourself
Why is 'pick two of C, A and P' a misleading way to describe the CAP theorem?
Free resources
- Consistency models (Jepsen)
- Eventually Consistent, Revisited (Werner Vogels)
- CAP theorem (Wikipedia)