CAP & PACELC
The CAP theorem stated precisely — consistency, availability and partition tolerance — what it does and doesn't say, CP vs AP systems, the PACELC extension with latency trade-offs, and how real databases are classified.
The CAP theorem (Eric Brewer's conjecture, 2000; proven by Gilbert and Lynch, 2002) is the most quoted — and most misquoted — result in distributed systems.
The three properties
| Property | Precise meaning |
|---|---|
| C — Consistency | Linearizability: every read sees the most recent completed write; the system behaves like a single copy of the data |
| A — Availability | Every request to a non-failed node receives a (non-error) response — eventually, with no time bound |
| P — Partition tolerance | The system keeps operating even if the network drops arbitrary messages between nodes |
What CAP actually says
When a network partition happens, a system must choose between consistency and availability.
Client 2 reads from node B, which can't reach A. B can:
- Refuse (error or wait until the partition heals) → stays consistent, sacrifices availability: a CP choice.
- Answer with its possibly stale value
x = 0→ stays available, sacrifices consistency: an AP choice.
There's no third option. That's all CAP says.
Common misreadings
- "Pick any two of three." Partitions aren't optional in a real network — you can't choose to "not tolerate" them. So the real choice is C or A during a partition. A "CA" system is just a single-node system (or one that breaks when partitioned).
- It's not a permanent label. When there's no partition, a system can provide both C and A. And systems can choose differently per operation (strong reads for payments, eventual reads for feeds).
- CAP's C is linearizability, not the "C" in ACID (which means invariants are preserved).
- CAP's A is very strict (every non-failed node must answer). Many "CP" systems are highly available in practice — a Raft cluster with a healthy majority keeps working; only the minority side refuses.
CP vs AP in practice
| CP-leaning | AP-leaning |
|---|---|
| ZooKeeper, etcd, Consul (coordination) | Cassandra, Riak, Dynamo-style stores (default settings) |
| Spanner, CockroachDB, TiDB, YugabyteDB | DNS, CDNs, caches |
| MongoDB with majority reads/writes | CouchDB, offline-first mobile sync |
| HBase | Shopping carts, social feeds, presence |
Choose CP when stale or conflicting data causes real harm: money, inventory, uniqueness constraints, leader election, locks. Choose AP when uptime matters more than perfect freshness, and conflicts can be merged later (CRDTs).
PACELC: the trade-off you face every day
Partitions are rare. Daniel Abadi's PACELC (2010) adds the trade-off that exists all the time:
If there's a Partition, choose Availability or Consistency; Else (normal operation), choose Latency or Consistency.
Keeping replicas strongly consistent requires coordination — waiting for other replicas (possibly in other regions) before acknowledging. That costs latency on every request, partition or not.
| System | During partition (PA/PC) | Normal operation (EL/EC) | Classification |
|---|---|---|---|
| DynamoDB, Cassandra (default) | Availability | Latency | PA/EL |
| MongoDB (default) | Availability* | Consistency (reads from primary) | PA/EC |
| Spanner, CockroachDB | Consistency | Consistency | PC/EC |
| PNUTS (Yahoo) | Consistency | Latency | PC/EL |
*Behaviour depends heavily on configuration. Many databases make the trade-off tunable:
-- Cassandra: per-query consistency level
CONSISTENCY ONE; -- fast, may be stale (EL)
CONSISTENCY QUORUM; -- R + W > N: reads see the latest write (EC)With N replicas, writes acknowledged by W and reads querying R, R + W > N guarantees read and write sets overlap, so a read sees the latest acknowledged write (see Replication).
- CAP: during a network partition, choose consistency (linearizability) or availability.
- Partition tolerance isn't optional; "CA" only describes non-distributed systems.
- CAP's C and A are strict definitions; real systems sit on a spectrum and can choose per operation.
- PACELC adds the everyday trade-off: without partitions, consistency costs latency.
- Many databases make the choice tunable (quorums, consistency levels).
QExplain the CAP theorem.medium
In a distributed data store, when a network partition separates nodes, you must choose between consistency — every read reflects the latest write, as if there were one copy — and availability — every non-failed node still responds. Since partitions can't be prevented, the real decision is how to behave during one: refuse some requests to stay consistent (CP) or answer with possibly stale data (AP). When there's no partition, both can be provided, though PACELC notes consistency then costs latency.