CAP and PACELC
What the CAP theorem actually says, why PACELC is more useful day to day, and how to place real databases.
15 min readCAP, stated precisely
CAP says that when a network partition separates replicas, a system must choose between consistency (linearizable reads and writes) and availability (every non-failed node answers every request). It is not a choice of two out of three: partitions are not optional in a distributed system, so the real question is what you do during one. A CP system refuses or delays some requests on the minority side to stay correct. An AP system answers everywhere and reconciles divergent data later.
PACELC: the normal case matters more
Partitions are rare; latency is constant. PACELC extends CAP: if there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency. Even with a healthy network, a strongly consistent write must wait for a majority of replicas, and if replicas are in different regions that wait is 50 to 150 ms. That latency cost is paid on every request, all year.
- Cassandra and DynamoDB defaults: PA/EL, available and fast, eventually consistent
- Spanner and CockroachDB: PC/EC, consistent always, paying cross-replica latency on writes
- Many systems are tunable per request, such as Cassandra's QUORUM versus ONE
Choosing per feature
A single product can mix choices. A shopping cart can be AP: accept additions during a partition and merge later, because losing a sale is worse than a duplicated item. Checkout payment capture should be CP: refusing for a minute is better than charging twice. Write down for each feature what happens to users during a partition, and what latency budget each write has in normal operation. A profile page might accept stale reads for minutes during a partition, while a username claim must fail rather than risk two owners.
Key takeaways
- CAP is about behaviour during a partition: refuse some requests or serve possibly stale data
- PACELC adds the everyday trade-off between latency and consistency
- Most databases can be tuned per request, so decide per feature
- Pay for consistency where a wrong answer is worse than a slow or failed one
Sign in to track lessons and earn badges.