CAP & PACELC
When the network splits, you must choose between staying consistent and staying available. And even when it doesn't, you still choose.
CAP & PACELC in 30 seconds
- CAP: during a network partition, a system can stay consistent or stay available — not both.
- Partition tolerance isn't optional in a real distributed system, so the real choice is C vs A when a partition hits.
- CP: refuse or block requests to avoid stale data — fits money, inventory, bookings.
- AP: keep answering and reconcile later — fits feeds, likes, carts, catalogs.
- PACELC extends it: if Partition then A or C, Else (normal operation) Latency or C.
- The everyday trade is the 'else' branch — latency vs consistency — and you tune it per capability, not system-wide.
Two shopkeepers who can't phone each other
Imagine a shop with two tills — one at the front, one at the back — that normally share a running count of stock over an intercom. A customer at the front buys the last of something; the front till tells the back till, and both agree 'zero left.' Now the intercom line goes dead. A customer walks up to the back till wanting that same item. The clerk has two choices, and only two. She can say 'I can't be sure we still have it — please wait' (refusing to risk selling something already gone), or she can say 'sure, here you go' and hope the front till didn't just sell it (staying helpful, but risking overselling).
There is no third option while the line is down. That dead intercom is a network partition, and the clerk's dilemma — be safe and stall, or be helpful and risk being wrong — is the entire CAP theorem in one scene. The rest of this page is that shop, made precise.
The problem it solves
Once your data lives on more than one machine, the network between them can fail. The CAP theorem names the uncomfortable truth: during a network partition, a distributed system can keep data consistent or keep serving requests (available), but not both. It forces you to decide, in advance, how your system behaves when nodes can't talk to each other.
The three letters, plainly
Consistency (C): every read sees the most recent write — all nodes agree. Availability (A): every request gets a non-error response, even if it might be stale. Partition tolerance (P): the system keeps working despite messages being lost between nodes. Since partitions will happen in any real distributed system, P is not optional — which means the real choice is between C and A during a partition.
Why 'pick any two' is the wrong mental model
CAP is usually drawn as a triangle with the tagline 'pick two of three,' which quietly suggests you could choose C and A and give up partition tolerance. You can't — not in any system where the machines talk over a real network, because networks drop packets, links fail, and nodes get isolated whether you planned for it or not. Partitions aren't a feature you opt into; they're weather. So the honest reading isn't 'pick two.' It's: partitions will happen; when one does, do you give up C or give up A? That single question is all CAP really asks.
// A replica receives a read, but it's partitioned from its peers.
// It cannot know if a newer write happened on the other side.
on read(key):
if cannot_reach_quorum(): # the partition case
// CP: safety first
return ERROR_or_WAIT # refuse rather than risk stale data
// --- OR ---
// AP: availability first
return local_value # answer now, might be out of date
else:
return consistent_value # normal operation: no dilemma
// You pick ONE of the two branches above, in advance, per capability.
// That pre-decision IS your CAP stance.CP vs AP in practice
| Choice | During a partition | Pros | Cons | Fits |
|---|---|---|---|---|
| CP (consistency) | Refuse or block requests that can't be made consistent. | Never returns wrong/stale data. | Some requests fail or wait during the partition. | Bank balances, inventory counts, bookings. |
| AP (availability) | Keep answering, accept temporary disagreement. | Always responsive; heals later. | Reads can be stale; conflicts must be resolved. | Feeds, likes, carts, product catalogs. |
Notice the choice is per capability, not per company. The same shopping site is CP where it matters — it will not oversell the last concert ticket or let an account balance go wrong — and happily AP where it doesn't, showing a 'like' count that's a few seconds stale or a product description that lags. A thoughtful design draws this line feature by feature.
How quorums turn the knob
CP and AP aren't just philosophy — you implement them with quorums: how many replicas must acknowledge a read or a write before you count it as done. Tune the quorum sizes and you slide between consistency and availability.
N = 3 // replicas per key
// CP-leaning: require overlapping quorums so a read always sees
// the latest acknowledged write. R + W > N guarantees overlap.
W = 2 // a write must be acked by 2 replicas
R = 2 // a read must agree across 2 replicas
// 2 + 2 > 3 -> every read quorum shares a node with every write quorum
// AP-leaning: shrink the quorums so you stay up during a partition,
// at the cost of possibly reading stale data.
// W = 1, R = 1 -> 1 + 1 < 3 -> fast and available, not consistentThe gap CAP leaves: the other 99.9% of the time
Here's CAP's blind spot. Partitions are rare — most systems go months without a real one. CAP only tells you what to do during that rare event and says nothing about normal operation, which is when your users actually live. But even with the network perfectly healthy, you still face a trade: to answer a read, do you wait for all replicas to agree (slower, but consistent) or reply from the nearest replica right away (faster, but possibly stale)? CAP has no vocabulary for that everyday choice. That gap is exactly what PACELC fills.
Why PACELC is the better lens
CAP only describes the partition case, which is rare. PACELC extends it: if Partition, choose Availability or Consistency; Else (normal operation), choose Latency or Consistency. This captures the everyday trade you actually make far more often — whether to wait for all replicas to agree (more consistent, slower) or answer from the nearest replica (faster, possibly stale). Most of your users feel the 'else' branch, not the partition.
if PARTITION:
choose Availability or Consistency # the rare CAP moment
else:
choose Latency or Consistency # EVERY normal request
// Common stances, named:
// PA/EL -> Dynamo, Cassandra: available + fast, eventual consistency
// PC/EC -> HBase, traditional RDBMS: consistent even if slower / blocking
// PA/EC -> MongoDB (tunable): available under partition, consistent when healthy
// 'The else branch is where your users live.'It's a spectrum, not a switch
Even 'consistency' isn't one thing you turn on or off. Between 'every read is bang up to date' (strong) and 'reads might be stale for a while' (eventual) sit useful middle grounds — read-your-own-writes, monotonic reads, bounded staleness. Picking a CAP/PACELC stance is really picking where on this spectrum each capability sits, trading freshness for speed and availability.
Choosing a stance per capability
| Capability | Stance | Reasoning |
|---|---|---|
| Account balance / payments | CP (and EC) | A wrong balance is unacceptable — refuse rather than risk it |
| Inventory for a flash sale | CP | Overselling the last item costs money and trust |
| Social feed / timeline | AP (and EL) | A few seconds stale is invisible; being down is not |
| Like / view counters | AP (and EL) | Approximate is fine; speed and uptime win |
| Product catalog | AP (and EL) | Reads dominate; a lagging description is harmless |
| User session / auth token | CP-ish (read-your-writes) | You must see your own just-made change immediately |
CAP and PACELC aren't abstract theory — they're the vocabulary for the single most important trade in distributed data: when you can't have everything, which guarantee do you give up, and where?
Why it matters
- Every distributed data decision eventually reduces to this question, so it's the lens you reason with constantly.
- Naming CP vs AP per capability is what separates a thoughtful design from a hand-wavy one.
- PACELC captures the latency-vs-consistency trade you make every day, not just during the rare partition.
If ignored
- Treating CAP as 'pick any two of three' produces confident but wrong design answers.
- Applying one consistency choice system-wide makes money paths stale or feeds needlessly slow.
- Ignoring the PACELC 'else' branch means missing the trade that actually governs normal operation.
Where it fits
- Sits above the data tier as the reasoning framework behind replication and store selection.
- Applied per capability — CP for the money path, AP for the feed — not once for the whole system.
- The theory that explains why replication, consistency models, and store choices trade off as they do.
Related topics
- Replication: the mechanism where the C-vs-A choice physically plays out
- Consistency models: the spectrum of guarantees the 'C' in CAP points to
- SQL vs NoSQL: ACID-vs-BASE is this same trade surfacing at the store level
- Availability & reliability: what the 'A' in CAP costs and protects
Interview lens
Questions it unlocks
- Is your system CP or AP, and why?
- What happens to writes when a replica can't reach the leader?
- Where would you accept eventual consistency and where wouldn't you?
60-second answer
I start by noting partition tolerance isn't optional in a distributed system, so CAP reduces to: during a partition, do I sacrifice consistency or availability? For money, inventory, or bookings I go CP — I'd rather fail a request than double-sell. For feeds, likes, or catalogs I go AP — stay responsive and reconcile later. Then I bring up PACELC, because the trade I make all day isn't the rare partition, it's latency versus consistency during normal operation, and I'd tune that per capability rather than system-wide.
Common traps
- Describing CAP as 'pick any two of three' and treating P as optional.
- Applying one consistency choice to the whole system instead of per capability.
- Forgetting that the common case is the PACELC 'else' latency-vs-consistency trade.