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.

Worth knowing

The theorem is about what happens during a network partition. With no partition there is no trade to make.
CP: refuse to answer rather than answer wrongly. AP: answer from what this node knows and reconcile later.
'Pick two of three' is the famous phrasing and a misleading one. Partitions are not optional, so the real choice is C or A.
PACELC extends it: else, when there is no partition, the trade is latency against consistency — and that one is always live.

Overview

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.

In this guide
  1. Define the guarantees precisely
  2. What the choice looks like
  3. What CAP does not say
  4. Turn the theorem into a product requirement
  5. Further reading

Define the guarantees precisely

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.

What the choice looks like

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.

What CAP does not say

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.

Turn the theorem into a product requirement

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.

Further reading

Check yourself

0 of 3

Answer without scrolling back up.

  1. What is wrong with 'pick two of three'?

  2. A CP system during a partition will:

  3. What does the 'ELC' half of PACELC describe?

Cheat sheet

The CAP Theorem

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.

DATABASE · vizlearn.in/database/cap_theorem.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.