CAP Theorem Explained: Consistency, Availability, Partitions
A distributed system can have two of three. Learn what the theorem actually says, the common misreading, and the PACELC extension.
By Velloreth
The theorem
A distributed system cannot guarantee all three of:
- Consistency — every read sees the most recent write
- Availability — every request gets a response
- Partition tolerance — the system keeps working when a message is lost
The key insight: a network partition is a fact, not a choice. A cable is cut, a switch fails, a packet is dropped. So the real decision is what the system does during a partition.
The common misreading
“Pick two of three” is misleading.
Why: the trade-off only applies during a partition. When the network is healthy, a system can be both consistent and available.
The accurate statement: during a partition, choose consistency or availability.
Network healthy -> consistent AND available
Network partition -> consistent OR available
Most systems are not purely one or the other. A database can be configured to require a quorum for a write, which makes it CP, or to accept a write on any node, which makes it AP.
CP
A CP system refuses a request it cannot serve consistently.
The behaviour during a partition: the minority side stops accepting writes, so the data stays correct and the service is unavailable on that side.
The examples: a system with a quorum write, a consensus-based store, a relational database with synchronous replication.
The use case: a bank balance, an inventory count, a unique username.
The cost: an unavailable service during a partition.
AP
An AP system answers with the data it has.
The behaviour during a partition: both sides accept writes, and the values diverge. The conflict is resolved later.
The examples: a Dynamo-style store, a multi-master replication, a cache.
The use case: a social feed, a product catalogue, a like count.
The cost: a stale read, and a conflict to resolve.
The conflict resolution: last-write-wins, a vector clock, or a merge function.
The comparison
| Concern | CP | AP |
|---|---|---|
| During a partition | refuse | answer |
| Data | correct | possibly stale |
| Availability | reduced | kept |
| Conflict | none | must be resolved |
| Example | bank balance | social feed |
PACELC
CAP covers only the partition case. PACELC extends it.
If Partition, choose Availability or Consistency; Else, choose Latency or Consistency.
The insight: even without a partition, a consistent write must wait for a quorum, which adds latency.
The trade-off in the normal case:
- A consistent read waits for the replicas to agree, which is slower
- A fast read may return a stale value
The examples:
| System | Partition | Normal |
|---|---|---|
| DynamoDB | PA | EL |
| Cassandra | PA | EL |
| MongoDB (majority) | PC | EC |
| Spanner | PC | EC |
A system that is PC/EC is consistent in both cases and pays with availability and latency.
The consistency spectrum
Consistency is not binary. The useful levels:
Strong consistency — every read sees the latest write.
Read-your-writes — a client sees its own writes.
Monotonic reads — a client never sees an older value than one it already saw.
Eventual consistency — the replicas converge, with no bound on the delay.
Causal consistency — a write that depends on another is seen after it.
The practical point: a system can offer a weaker guarantee and a better latency, and the application may not need the strongest one.
Quorums
A quorum is the number of nodes that must agree.
N = replicas
W = nodes that must acknowledge a write
R = nodes that must respond to a read
If W + R > N, a read sees the latest write.
The configurations:
| W | R | Property |
|---|---|---|
| N | 1 | fast read, slow write, consistent |
| 1 | N | fast write, slow read, consistent |
| majority | majority | balanced |
| 1 | 1 | fast, eventually consistent |
A quorum is how a system is tuned between consistency and latency without changing the code.
Choosing
A payment or an inventory: CP. A stale value is worse than an error.
A feed or a catalogue: AP. A stale value is acceptable and an error is not.
A session store: AP with a short TTL.
A configuration store: CP, because a wrong configuration is worse than a delay.
The question to ask: what happens if this value is stale for a second? If the answer is “nothing”, AP is fine.
Common mistakes
Saying “we chose AP and CA”. CA is not an option in a distributed system, because a partition happens.
Applying CAP to a single node. There is no partition to tolerate.
Assuming eventual consistency means no consistency. It means the replicas converge, and the application must tolerate the window.
Ignoring the latency trade-off. PACELC is the part that applies every day.
A quorum that is not a majority. Two quorums can overlap incorrectly and a read can miss a write.
Treating the choice as permanent. Most systems are tunable per operation.
Forgetting the conflict resolution. An AP system that accepts divergent writes must have a merge rule.
A quotable summary
The CAP theorem says a distributed system cannot guarantee consistency, availability and partition tolerance at the same time, and since a partition is a fact, the real decision is what the system does during one: refuse the request to stay consistent, or answer with possibly stale data to stay available. PACELC extends it to the normal case, where a consistent write must wait for a quorum and therefore costs latency. Most systems are tunable rather than purely CP or AP, and the right choice depends on the cost of a stale read against the cost of an unavailable service.
Related reading
For the related topics, see eventual-consistency-guide and replication-vs-sharding. For the broader context, database-sharding-basics and transactions-and-acid.