The CAP Theorem
When the network splits, a distributed store can stay correct or stay answering. It cannot do both.
The CAP Theorem
This module needs JavaScript: it steps through two transactions rather than showing a finished picture.
When the network splits, a distributed store can stay correct or stay answering. It cannot do both.
This module needs JavaScript: it steps through two transactions rather than showing a finished picture.
CAP concerns a distributed service during a network partition: some nodes cannot exchange messages. It asks whether the system can preserve a single-copy view of data and still return a response to every request sent to a non-failing node. The theorem is often compressed into “pick two,” which hides the condition that makes the trade-off relevant: a partition.
CAP concerns a distributed service during a network partition: some nodes cannot exchange messages. It asks whether the system can preserve a single-copy view of data and still return a response to every request sent to a non-failing node. The theorem is often compressed into “pick two,” which hides the condition that makes the trade-off relevant: a partition.
Consistency here means linearizability: each operation appears to take effect atomically at one point between its call and response, respecting real-time order. It is stronger and more specific than the broad database use of “consistency” in ACID.
Availability means every request to a non-failing node eventually receives a valid response. Returning a stale value is available under this definition, but may violate linearizability.
Partition tolerance means the system continues to operate despite dropped or delayed messages between parts of the cluster. In a real distributed system, a partition cannot simply be wished away.
Suppose a user updates a balance on one side of a partition while another client reads from the isolated side. A system that refuses to answer that read can preserve one agreed order of operations, sacrificing availability for that request. A system that returns the isolated replica's local value stays responsive, but may return stale data. Once communication returns, replicas can reconcile, though application conflicts may still need resolution.
This is a choice among guarantees during the partition, not a permanent label for a whole product. Different operations or configurations can make different trade-offs.
CAP does not mean a database can offer only two of consistency, availability, and partition tolerance in normal operation. It also does not tell you which product to select, how much staleness is acceptable, or how the system behaves when there is no partition. PACELC extends the discussion by asking about latency versus consistency even when the network is healthy.
For practical design, write down what a read may return during a failure, whether writes may be rejected, and how recovery works. Replication settings and read routing determine those behaviors; see replication and lag.
For a shopping cart, is it acceptable to show a slightly stale copy during a regional network failure, or should the request wait or fail until the latest update is available? That is a concrete consistency-versus-availability question. Specify the behavior for reads and writes separately, including timeout behavior and what happens after recovery. “Eventual consistency” only says that replicas may converge if updates stop and communication recovers; it does not define a maximum delay or settle concurrent conflicting writes. Document those details for the actual system.
Answer without scrolling back up.
What is wrong with 'pick two of three'?
Networks fail eventually, so P must be tolerated. The theorem constrains behaviour during that specific temporary failure, not design in general.
A CP system during a partition will:
Correct, and temporarily unavailable to anyone who cannot reach a quorum. The right choice when a wrong answer is worse than no answer.
What does the 'ELC' half of PACELC describe?
Confirm every write with remote replicas and be slower, or acknowledge locally and be briefly stale. It is the synchronous-versus-asynchronous replication choice.
Walk through the CAP theorem with a two-node example, see which two guarantees you keep, and learn what the theorem does not actually say.