When the network breaks, a distributed system must choose: stay consistent or stay available.
The CAP theorem says a distributed data system cannot promise all three of these at the same time when the network breaks:
Networks do break, so partition tolerance is not optional. The real choice is: when a partition happens, do we choose Consistency (CP) or Availability (AP)?
In a distributed system, data is stored on many machines (copies, called replicas). The machines talk over a network. Sometimes that network fails between some machines. This is called a partition.
If your data is on more than one machine, messages can be lost, cables break and servers pause. You cannot buy a network that never fails. So any real distributed system must handle P. That leaves CP or AP.
CAP is a way of thinking. It helps us choose the right database and design for each feature.
| Type | During a partition | You get | You give up | Examples (typical) |
|---|---|---|---|---|
| CP | Refuses some requests | Correct, latest data | Availability | Systems built on consensus: ZooKeeper, etcd, HBase, MongoDB (default settings) |
| AP | Keeps answering | Always responds | Latest data (stale reads) | Cassandra and DynamoDB (default settings), CouchDB |
| CA | Not possible once data is on many machines | A single node database | Partition tolerance | A single-server SQL database |
AP systems usually promise eventual consistency: if nobody writes for a while, all copies will become equal. Conflicts are solved with rules such as last write wins, version numbers (vector clocks) or merge types (CRDTs).
CAP only talks about partitions. PACELC adds more: if there is a Partition, choose Availability or Consistency; Else (normal times), choose Latency or Consistency. Waiting for every replica to agree makes writes slower. So even on a good day we trade speed for correctness.
| Term | Meaning in easy words |
|---|---|
| Distributed system | Many computers working together as one system. |
| Replica | A copy of the data on another machine. |
| Partition | A network failure that stops some nodes from talking to others. |
| Consistency (CAP) | Every read returns the latest write (or an error). |
| Availability (CAP) | Every request to a working node gets a non-error answer. |
| Strong consistency | After a write, everyone sees it right away. |
| Eventual consistency | Copies become equal after some time if writes stop. |
| Stale read | Reading an old value. |
| Quorum | The minimum number of nodes that must agree. Usually a majority. |
| Consensus | A way for nodes to agree on one value (Raft, Paxos). |
| Split brain | Two parts of a system both think they are in charge after a partition. |
| PACELC | CAP plus the latency vs consistency trade-off when there is no partition. |
| Choice | We gain | We lose |
|---|---|---|
| CP | Always correct | Some downtime during a partition |
| AP | Always answers | May serve stale data, needs conflict handling |
| Strong consistency (no partition) | Simple for developers | Higher write latency |
| Eventual consistency | Low latency, high uptime | More complex application logic |