The CAP theorem says that when the network between replicas breaks (a partition), a replicated data store must choose: keep answering and risk returning stale data (availability), or refuse some requests so that nobody ever sees stale data (consistency). PACELC adds the half that matters every day: even when the network is healthy, you trade latency against consistency. Together they are the vocabulary for every replication decision you will make.
Think of it like
Two bank branches and a phone line
Two branches share one customer's account and sync over a phone line. The line goes dead. A customer walks into branch A to withdraw cash. Branch A can refuse until the line is back (consistent but unavailable), or hand over the cash based on its own ledger and hope branch B didn't just do the same (available but possibly inconsistent). There is no third option: no amount of cleverness lets A know what B did while the line is down.
The three properties, precisely
CAP was conjectured by Eric Brewer in 2000 and proven by Seth Gilbert and Nancy Lynch in 2002. The proof uses very specific definitions, and most confusion about CAP comes from using looser everyday meanings of the same words.
- Consistency (C)
- Linearizability: the system behaves as if there were a single copy of the data and every operation took effect atomically at some instant between its request and its response. Once any read returns a value, every later read (in real time) returns that value or a newer one.
- Availability (A)
- Every request received by a non-failing node eventually gets a non-error response. Not "most requests", not "99.99% uptime": every reachable node must answer.
- Partition tolerance (P)
- The system keeps meeting its guarantees even if the network drops an arbitrary number of messages between nodes. A partition splits the nodes into groups that cannot talk to each other.
The proof in one picture
Take two replicas, A and B, both holding x = 1, and cut the link between them. Client 1 writes x = 2 to A; Client 2 then reads x from B. B has only two choices: answer with what it has (x = 1, stale, so not linearizable) or refuse to answer (not available). Press play on each flow to see both outcomes. In the simulation above, introduce a partition and watch how each mode treats the same requests.
Why P isn't optional
The popular phrasing "pick two of three" suggests you could pick C and A and skip P. In a distributed system you can't: switches fail, cables get cut, cloud availability zones lose connectivity, and a process frozen by a 30-second garbage-collection pause is indistinguishable from one on the far side of a partition. You don't get to opt out of partitions; you only get to decide how to behave when one happens.
- A "CA" system is really a single-node system, or one that assumes the network never fails and behaves unpredictably when it does.
- The real choice is therefore CP or AP, made at partition time. When there is no partition, a well-designed system can offer both C and A.
- Brewer himself wrote in 2012 ("CAP Twelve Years Later") that "2 of 3" is misleading, because partitions are rare and the choice can be made per operation and per subsystem.
CP vs AP in practice
CP: consistency first
- Minority side rejects writes (and linearizable reads) during a partition
- Built on consensus or a single authoritative owner per key
- Examples: ZooKeeper, etcd, Consul KV, HBase, Spanner, CockroachDB
- Use for locks, leader election, configuration, metadata, money
AP: availability first
- Every reachable replica keeps accepting reads and writes
- Replicas diverge and reconcile later (last-writer-wins, siblings, CRDTs)
- Examples: Cassandra, Riak, CouchDB, DNS, DynamoDB's default reads and global tables
- Use for carts, feeds, likes, presence, metrics
- ZooKeeper orders all writes through a leader (ZAB). Plain reads are served locally by whichever server the client is connected to and can be stale; call
sync()before a read when you need the latest value. - etcd serves linearizable reads by default (the leader confirms it is still leader before answering) and offers cheaper
serializablereads that may be stale. - HBase assigns each region to exactly one RegionServer. If that server dies, the region is unavailable until it is reassigned: a textbook CP trade.
- Cassandra lets each query pick a consistency level, from
ONE(fast, may be stale) toALL(slow, fails if any replica is down). See Quorums & Leaderless Replication. - DynamoDB returns eventually consistent reads by default and offers strongly consistent reads on request (
ConsistentRead: true). Multi-region global tables resolve concurrent writes with last-writer-wins by default.
Common misconceptions
| Myth | Reality |
|---|---|
| "Pick any two of C, A and P." | P is not a choice. You choose how to behave during a partition. Without one, you can have C and A. |
| "CP systems are unavailable." | Only the minority side, only during the partition, and only for operations that need consistency. |
| "AP systems are inconsistent." | They are eventually consistent, and many add session guarantees such as read-your-writes. See Consistency Models. |
| "Availability means high uptime." | CAP availability means every non-failing node answers. A Raft cluster can have 99.99% uptime yet is not CAP-available. |
| "Every system is either CP or AP." | Many systems are neither (e.g. async replication with failover can lose acknowledged writes and is not linearizable), and many let you choose per request. |
| "CAP covers all the trade-offs." | CAP considers one fault (partitions) and one model (linearizability). It says nothing about latency, which is where PACELC comes in. |
PACELC: the trade-off that exists every day
Partitions are rare. Latency is constant. Daniel Abadi's PACELC (2010) extends CAP: if there is a Partition, choose Availability or Consistency; else, choose Latency or Consistency. A synchronous write to a quorum spread across zones costs round trips on every request, whereas answering from the nearest replica is fast but may be stale.
| System | During a partition | Normal operation | Notes |
|---|---|---|---|
| Cassandra, Riak | PA | EL | Default levels favor speed; tunable per query |
| DynamoDB (default reads) | PA | EL | Strongly consistent reads are opt-in and cost twice the read capacity |
| ZooKeeper, etcd | PC | EC | Writes need a majority; etcd reads are linearizable by default |
| HBase, Bigtable | PC | EC | One owner per region or tablet |
| Spanner, CockroachDB | PC | EC | Consensus per shard; pays latency for strong guarantees |
| MongoDB | Configurable | Configurable | Behavior depends on readConcern and writeConcern |
Tunable consistency
Many stores let each request pick its own point on the spectrum. In Dynamo-style systems each key lives on N replicas; a write waits for W acknowledgments and a read for R replies. When R + W > N the read and write sets overlap, so reads see the latest acknowledged write in the common case. The details are in Quorums & Leaderless Replication.
-- Strong-ish: with replication factor 3, QUORUM = 2 replicas
CONSISTENCY QUORUM;
INSERT INTO carts (user_id, items) VALUES (42, ['book']);
SELECT items FROM carts WHERE user_id = 42; -- overlaps the write quorum
-- Fast: any single replica answers, possibly with stale data
CONSISTENCY ONE;
SELECT items FROM carts WHERE user_id = 42;| System | Fast option | Strong option |
|---|---|---|
| Cassandra | ONE, LOCAL_ONE | QUORUM, LOCAL_QUORUM, ALL; SERIAL for compare-and-set |
| DynamoDB | Default eventually consistent read | ConsistentRead: true |
| MongoDB | w: 1, readConcern: "local" | w: "majority", readConcern: "majority" or "linearizable" |
| etcd | Serializable read (--consistency=s) | Linearizable read (default) |
| ZooKeeper | Plain read from the connected server | sync() then read |
Choosing per feature
| Data | Choice | Why |
|---|---|---|
| Seat or ticket inventory | CP | Double booking is worse than a brief error |
| Account balances, payments | CP | Money must not be created or lost |
| Leader election, distributed locks | CP | Two leaders (split brain) corrupts data |
| Shopping cart | AP | Merge divergent carts; never block adding an item |
| Likes, view counts | AP | Approximate and late is fine; use CRDT counters |
| Social feed, profile pages | AP + read-your-writes | Stale for others is fine, but users must see their own changes |
Key takeaways
- CAP: during a network partition, a replicated store must choose between linearizable consistency and availability of every node.
- Partitions are not optional in a distributed system, so the meaningful labels are CP and AP, chosen per operation or per subsystem.
- CP systems keep the majority side working; AP systems keep every side working and reconcile divergent replicas later.
- PACELC adds the everyday trade-off: without partitions, you still pay latency for consistency.
- Tunable consistency (quorums, per-request read modes) lets one database serve both strong and fast paths.
Common pitfalls
- Confusing CAP consistency (linearizability) with ACID consistency (invariants).
- Claiming a distributed system is "CA": it just means the partition behavior is undefined.
- Treating CAP availability as uptime; a CP system can be highly available in the everyday sense.
- Labeling an entire product CP or AP instead of deciding per data type and per operation.
- Assuming quorum reads are fully linearizable; edge cases such as sloppy quorums and concurrent writes break that.
Interview tips
- State the precise definitions of C and A first; it signals depth immediately.
- Explain what each side of a partition does in your design: which requests fail, which succeed, and how data reconciles afterward.
- Bring up PACELC unprompted when discussing cross-region replication latency.
Real-world applications
- Choosing between etcd/ZooKeeper (CP) and Cassandra/DynamoDB (AP-leaning) for a feature.
- Designing multi-region deployments: synchronous replication (PC/EC) vs local writes with async replication (PA/EL).
- Setting per-query consistency levels in Cassandra, MongoDB and DynamoDB.
Test yourself
In the CAP theorem, what does "consistency" mean?
Related topics
Finished this lesson? Track it to see your progress on the roadmap.