The CAP theorem says that when a network partition splits a distributed system, each node must choose between consistency (every read sees the latest write or an error) and availability (every request gets a non-error response). You cannot have both during the partition. It is not a rule that you permanently pick two of three properties; it describes the forced choice a replicated system makes when some nodes cannot talk to others.

CAP theorem explained: the three properties

The theorem uses precise definitions, and most confusion comes from mixing them up with everyday meanings.

  • Consistency (C) means linearizability: the system behaves as if there is a single copy of the data, and every read returns the most recent completed write. This is different from the "C" in ACID, which is about preserving invariants within a transaction.
  • Availability (A) means every request received by a non-failing node eventually gets a non-error response. It does not mean "high uptime" in the SLA sense.
  • Partition tolerance (P) means the system keeps operating even when messages between nodes are lost or delayed indefinitely.

The CAP theorem guide goes deeper on the formal definitions.

Why partition tolerance is not optional

In any system that runs on more than one machine over a network, partitions happen: a switch fails, a cable is cut, a cloud zone loses connectivity, or a long garbage-collection pause makes a node look dead. You do not get to opt out of that. So the real question is never "which two of three?" but "when a partition happens, do we give up consistency or availability?"

When there is no partition, a well-built system can provide both consistency and availability. CAP only constrains behavior during the failure. See Partition tolerance for more on how partitions actually show up in practice.

A simple example of the CAP trade-off

Imagine a key-value store with two replicas, one in each of two data centers. A user writes balance = 100 to replica A. Before A can copy that write to replica B, the link between them fails. Now another user reads balance from replica B. B has two options:

  1. Refuse or block the read until it can confirm the latest value with A. The answer is never wrong, but the request fails or times out. That is choosing consistency (CP).
  2. Return the value it has, which may be stale. The request succeeds, but the answer may be out of date. That is choosing availability (AP).

There is no third option that is both correct and always answers. That is the whole theorem.

  Client 1                      Client 2
     |                             |
  write x=100                   read x
     v                             v
 +---------+    X  link down  +---------+
 | Node A  | ---- X ------- | Node B  |
 | x = 100 |                  | x = 50  |
 +---------+                  +---------+

 CP choice: Node B returns an error or waits
 AP choice: Node B returns x = 50 (stale)

CP vs AP systems with real-world examples

Real systems are rarely purely one or the other, and many are configurable. Still, their default behavior during a partition tends to lean one way.

Category Behavior during a partition Example systems (typical configuration) Good fit for
CP Minority side rejects or blocks requests ZooKeeper, etcd, HBase, a single-primary relational database with synchronous failover Leader election, config, locks, financial ledgers
AP All sides keep serving, reconcile later Cassandra and DynamoDB-style stores at low consistency levels, DNS, many caches Shopping carts, feeds, metrics, presence

A few notes to keep this accurate:

  • Consensus-based systems like etcd and ZooKeeper use a quorum. Nodes on the minority side of a partition stop accepting writes, which is the CP choice.
  • Cassandra lets you choose per query. Reading and writing at QUORUM behaves closer to CP for that operation; ONE favors availability.
  • A single-node database is not really a CAP example at all, since there is nothing to partition. CAP applies once you replicate.

Choosing between consistency and availability

The choice should come from the business cost of each failure mode:

  • Is a stale or conflicting answer worse than no answer? Bank balances, inventory reservation, and unique username claims usually say yes. Lean CP.
  • Is an error worse than a slightly stale answer? Social feeds, product catalogs, like counts, and recommendations usually say yes. Lean AP and plan for eventual consistency.
  • Can you split the system? Most real applications mix both: the checkout path is CP while the product listing is AP.

AP systems also need a strategy for reconciling divergent writes after the partition heals, such as last-write-wins timestamps, version vectors, or merge-friendly data types (CRDTs). Choosing AP without a merge plan just moves the problem.

PACELC: what CAP leaves out

CAP says nothing about the normal case when there is no partition, yet that is where systems spend almost all their time. PACELC fills the gap:

If there is a Partition, choose between Availability and Consistency; Else, choose between Latency and Consistency.

Even with a healthy network, keeping replicas strictly consistent means waiting for acknowledgments from other nodes, which adds latency. Skipping that wait makes requests faster but allows stale reads. Examples:

  • PA/EL systems favor availability during partitions and low latency otherwise, such as Dynamo-style stores at default settings.
  • PC/EC systems favor consistency in both cases, such as consensus-backed stores and many distributed SQL databases.
  • PA/EC and PC/EL combinations exist too, depending on configuration.

PACELC is often a more useful framing in design discussions, because the latency-versus-consistency trade-off affects every request, not just the rare partition.

Common misconceptions about the CAP theorem

  • "Pick any two of three." You cannot drop P in a distributed system, so the real choice is C or A during a partition.
  • "AP means no consistency." AP systems still converge; they just allow temporary divergence.
  • "CP means the system is down." Only the minority side, or nodes that cannot reach a quorum, refuse requests. The majority side keeps working.
  • "CAP consistency equals ACID consistency." They are different concepts with the same name.

If CAP comes up in a system design interview, state which operations need linearizable reads and which can tolerate staleness, then justify the choice with the business impact.

Key takeaways

  • CAP describes a forced choice during a network partition, not a permanent pick-two menu.
  • Consistency in CAP means linearizability; availability means every non-failing node responds.
  • CP systems reject some requests during partitions; AP systems answer but may return stale data.
  • Many databases are tunable per operation, so the choice can differ within one application.
  • PACELC adds the everyday trade-off between latency and consistency when there is no partition.

Frequently asked questions

What is the CAP theorem in simple terms?

When the network between parts of a distributed system fails, each part must either stop answering some requests to avoid returning wrong data, or keep answering and risk returning stale data. You cannot guarantee both correct and always-available answers during that failure.

Is MongoDB CP or AP?

With its default configuration of a single primary per replica set and majority write concern, MongoDB behaves closer to CP: if the primary is cut off from the majority, it steps down and writes pause until a new primary is elected. Relaxing read preference or write concern shifts it toward availability.

Why can't a distributed system be CA?

A CA system would have to assume the network never partitions. In any system spread across multiple machines, partitions eventually happen, so the system must decide how to behave when they do. A single-node database can be described as CA only because it is not distributed.

What is the difference between CAP and PACELC?

CAP only covers behavior during a partition. PACELC adds that, even without a partition, a system trades latency against consistency, because waiting for replicas to agree takes time. PACELC is often more useful for everyday design decisions.