The CAP theorem says: during a network partition, a replicated data store must choose between consistency and availability. A replicated data store keeps copies of the same data on several machines (nodes).
CAP names three properties:
- Consistency (C): every read sees the latest write. This is meant in the linearizable sense: the system behaves as if there is only one copy of the data.
- Availability (A): every request to a node that has not failed gets a non-error response.
- Partition tolerance (P): the system keeps working when the network drops messages between nodes. A partition is this split in the network.
In a distributed system, network partitions will happen. So P is not optional. During a partition, you must choose one of two options:
- CP: refuse or delay some requests, so the data stays consistent.
- AP: keep answering on both sides of the split. You accept that the two sides may diverge (hold different data), and you reconcile them later.
When there is no partition, you can have both C and A. CAP says nothing about this normal case. PACELC adds that part. The choice can also differ per operation. For example, a payment write might be CP, while a product view is AP.
- C means linearizable reads, and A means every live node responds.
- Partitions cannot be avoided, so P is a given.
- During a partition, you must choose C or A.
- Without a partition, you can have both C and A.
- The choice can be different for each operation.