CAP Theorem Explained: Consistency, Availability & Partition Tolerance (Visualized)
The CAP theorem states that a distributed data store can provide at most two of three guarantees โ Consistency, Availability, and Partition tolerance โ at the same time. Because network partitions are unavoidable, the real choice is consistency versus availability. Here's what that means, with live animations.
The CAP theorem (also called Brewer's theorem) states that a distributed data store can simultaneously guarantee at most two of these three properties: Consistency, Availability, and Partition tolerance. It is one of the most cited โ and most misunderstood โ ideas in distributed systems.
The Three Guarantees
Consistency (C): every read receives the most recent write or an error. All nodes see the same data at the same time. Availability (A): every request receives a non-error response, without the guarantee that it contains the latest write. Partition tolerance (P): the system keeps operating even when the network drops or delays messages between nodes.
Why It's Really 'Pick C or A'
Here is the part most explanations skip: in any real distributed system, network partitions will happen โ cables fail, switches reboot, packets drop. So partition tolerance is not optional; you must design for it. That collapses the famous "pick two" into a single practical choice: when a partition occurs, do you favor consistency or availability?
A CP system refuses to answer (or rejects writes) on the side of the partition that can't confirm it has the latest data โ staying consistent at the cost of availability. An AP system keeps answering on both sides, possibly with stale data, and reconciles later. Watch both behaviors on the same partition:
CP, AP, and the Myth of CA
| Choice | Behavior during a partition | Example systems |
|---|---|---|
| CP | Reject reads/writes to stay consistent | etcd, ZooKeeper, HBase, MongoDB (default) |
| AP | Stay available, reconcile later (eventual consistency) | Cassandra, DynamoDB, Riak, CouchDB |
| CA | Only possible with no partition โ i.e. a single node | A single-node SQL database |
"CA" is effectively a myth for distributed systems: the moment you have more than one node communicating over a network, partitions are possible, so you cannot drop P. A single-node database is the only true CA system โ and it isn't distributed.
Beyond CAP: PACELC
CAP only describes behavior during a partition. PACELC extends it: if there is a Partition, choose between Availability and Consistency; Else (normal operation), choose between Latency and Consistency. This captures the everyday trade-off that strong consistency costs latency even when nothing is broken.
Consistency Is a Spectrum, Not a Switch
Modern systems tune this per operation. DynamoDB lets you request strongly consistent reads when correctness matters and eventually consistent reads when speed matters. The real engineering skill is identifying which data needs strict consistency (payments, inventory) and which can tolerate brief staleness (view counts, feeds).
Frequently Asked Questions
Can a system have all three of C, A, and P?
Not simultaneously. During a network partition you must give up either consistency or availability. When there is no partition, a well-designed system can offer both โ but it cannot guarantee all three at once under partition.
Is the CAP theorem still relevant?
Yes, as a mental model, but treat it as a starting point. PACELC and tunable consistency levels describe real systems more precisely. CAP's lasting lesson is: partitions are inevitable, so decide your partition behavior deliberately.
Is SQL CP and NoSQL AP?
Not reliably. It depends on configuration. A distributed SQL database can be CP, and some NoSQL stores can be tuned toward consistency. Judge each system by its replication and quorum settings, not its query language.
Partitions aren't a choice โ they're a fact of networks. CAP is really about what you do when one happens.
โ alokknight Engineering
