CAP Theorem
Understand what a network partition really forces you to choose—and what CAP does not say.
Partition occurs → preserve one answer or preserve every response
refresher
CAP says that when replicas cannot communicate, a distributed system cannot guarantee both a single consistent answer and a successful response from every reachable replica. It must choose per operation: reject or delay some work, or accept that answers may temporarily diverge.
What problem does CAP help us reason about?
Replicas normally coordinate over a network. Networks can delay, drop, or isolate messages while every machine appears healthy. Once two sides cannot communicate, neither can know whether the other side is down or merely unreachable.
CAP gives us language for the product decision hidden inside that uncertainty.
The three properties, plainly
- Consistency — every successful read behaves as if there were one up-to-date copy.
- Availability — every request reaching a healthy node receives a non-error response.
- Partition tolerance — the system continues with messages lost or delayed between groups of nodes.
Key trade-offs
| Choice | What you gain | What it costs |
|---|---|---|
| CP during partition | One authoritative answer and protected invariants | Some requests wait or fail |
| AP during partition | Every reachable region can keep serving | Conflicts or stale reads must be reconciled |
| Per-operation policy | Guarantees match business consequence | A more explicit application model |
What happens if?
Two regions lose connectivity
If both regions accept updates to the same record, the service remains available but may create conflicting versions. If only the elected region accepts writes, the system preserves one order but users in the isolated region cannot complete that operation.
The network is merely slow, not broken
The system cannot distinguish delay from failure with certainty. A timeout converts uncertainty into policy: wait longer for stronger confidence, or respond sooner with weaker freshness.
Where this appears in real systems
Banking ledgers often reject writes without authoritative coordination. Shopping carts and social feeds frequently accept temporary divergence. Many databases let teams select consistency per request rather than declaring the whole product “CP” or “AP.”
Senior interview modeWhy is ‘pick any two of CAP’ misleading?Show answer
Because partition tolerance is a condition imposed by the network, not a steady-state feature to casually disable. Before a partition, a system can provide both consistency and availability. During one, it must decide which successful operations preserve a single truth and which remain responsive.