CAP and Consistency
CAP is the most quoted and least understood theorem in system design. The naive reading — “pick two of consistency, availability, partition tolerance” — is wrong in a way that is easy to expose in an interview, and being the candidate who corrects it is a strong signal.
The 60-second answer
Section titled “The 60-second answer”CAP says that when a network partition occurs, a replicated system must choose between consistency (linearizability) and availability (every non-failed node returns a response). Partition tolerance is not optional — networks partition, so the real choice is only made during a partition. Outside a partition you can have both, and the interesting trade-off is then latency versus consistency, which is what PACELC adds: if Partition then Availability or Consistency, Else Latency or Consistency.
What the letters mean
Section titled “What the letters mean”| Letter | Formal meaning | Not this |
|---|---|---|
| C | Linearizability: every operation appears to take effect atomically at a single point in time, and reads see the latest write | “ACID consistency” (which is about invariants), or “all replicas identical” |
| A | Every request to a non-failing node receives a non-error response, in bounded time | “The system never goes down” |
| P | The network drops messages between nodes for some duration | “Servers crashing” |
Two of these are about behaviour during a partition. Real systems always have partitions, so a system that “chooses CA” is simply a system that has not been tested under partition — single-node databases are the honest example, and they are not distributed.
So the theorem is: during a partition, you cannot have both linearizability and availability. You either return an error (or block) to preserve consistency, or you return possibly-stale data to stay available.
PACELC
Section titled “PACELC”Daniel Abadi’s extension, which is more useful in practice:
If Partition: Availability or Consistency. Else: Latency or Consistency.
Even with no partition and no failure, keeping replicas consistent costs at least one round trip. A quorum write waits for the slowest of the majority; a leader-follower write waits for the leader and its replication. If you skip that wait, you are faster and less consistent.
| System | During partition | Else | Classification |
|---|---|---|---|
| Dynamo / Cassandra (default tuneable) | A | L | PA/EL |
| BigTable / HBase | C | C | PC/EC |
| MongoDB (majority write concern) | C | C | PC/EC |
| PostgreSQL with sync replica | C | C | PC/EC |
| Spanner | C | C (bounded by TrueTime) | PC/EC |
| Redis (async replication) | A | L | PA/EL |
Spanner is worth naming: it provides linearizability and external consistency by waiting out a bounded clock uncertainty, which is exactly “latency for consistency”.
Consistency models
Section titled “Consistency models”From strongest to weakest:
Linearizable (strong). Operations appear in a single global order consistent with real time. A completed write is visible to every subsequent read. Implemented with consensus (Raft, Paxos) or a single leader. Cost: coordination, and unavailability when a quorum is unreachable.
Sequential. All nodes agree on one order of operations, but that order need not match real time.
Causal. Operations that are causally related are seen by everyone in the same order; concurrent operations may be seen in different orders. This is usually the best deal available: it prevents “reply appears before the message it replies to” while staying available under partition. Implemented with version vectors or Lamport/logical clocks.
Read-your-writes. A client sees its own writes. Implemented by routing that client’s reads to the leader for a window, by sticky sessions, or by passing a version token and waiting for a replica to catch up.
Monotonic reads. A client never sees data go backwards in time. Implemented by pinning a client to a replica.
Eventual. Given no new writes, replicas converge. No bound on how long that takes. It is the weakest useful guarantee, and it is what most “fast” systems offer.
“Session guarantees” — read-your-writes, monotonic reads, monotonic writes, writes-follow-reads — are the practical middle ground, and mentioning them is a good signal because they map to what users actually notice.
Quorums
Section titled “Quorums”With N replicas, a write acknowledged by W and a read served by R:
R + W > N ⇒ the read set overlaps the write set ⇒ the read sees the latest acknowledged write| N | W | R | Behaviour |
|---|---|---|---|
| 3 | 3 | 1 | Fast reads, no tolerance for a single node loss on write |
| 3 | 2 | 2 | Balanced: survives one node failure, consistent reads |
| 3 | 1 | 1 | Fast, may read stale data |
| 5 | 3 | 3 | Tolerates two failures |
Quorum consistency is not linearizability. It gives you overlap, and therefore “read the latest
acknowledged write” for a completed write — but concurrent writes still need conflict resolution
(last-write-wins by timestamp, vector clocks, or CRDTs), and a failed write may have partially
applied. Sloppy quorums and hinted handoff weaken the guarantee further: W nodes acknowledged
may not be the N home replicas.
Also note: R + W > N says nothing about a write that returned an error. It may still be applied
on some replicas. That is why retries need idempotency, covered in
Idempotency.
Choosing per operation, not per system
Section titled “Choosing per operation, not per system”The strongest answers refuse to label a whole system:
“The order ledger is linearizable — a single Postgres primary with synchronous replication. The product catalogue is read from replicas and a cache; a two-second-stale price is fine to browse but the checkout reads the primary. The view counter is a sharded Redis counter and is eventually consistent, because nothing breaks if it lags.”
That is a design, not a slogan. Each line names the operation, the guarantee and the cost.
Follow-up questions
Section titled “Follow-up questions”- Why is “choose two of three” a bad summary of CAP?
- What does PACELC add that CAP does not?
- If
R + W > N, why might a read still not be linearizable? - How would you implement read-your-writes when reads go to a lagging replica?
- Redis fails over and loses the last second of writes. Is that a CAP trade-off?
- Where in a payment flow can you tolerate eventual consistency, and where absolutely not?
Common traps
Section titled “Common traps”- “CAP means pick two of three.” Partition tolerance is not a choice. The trade-off only exists during a partition, and only between linearizability and availability.
- “C in CAP is the same C as in ACID.” CAP’s C is linearizability. ACID’s C is constraint preservation.
- “MongoDB is CP” / “Cassandra is AP”. These are defaults and tunable. State the write concern and read concern you mean.
- “Eventual consistency means no consistency.” It means convergence with no time bound, which is a real guarantee you must design around.
- “Quorum reads are strongly consistent.” Only with overlap, no conflicts, and no sloppy quorum. Concurrent writes still need resolution.