What is the CAP Theorem

The CAP theorem states that a distributed system can guarantee at most two of three properties simultaneously: Consistency, Availability, and Partition tolerance. Since network partitions are unavoidable in practice, the real choice is between consistency and availability during a partition.

How it works

The three properties:

  • Consistency — every read returns the most recent write. All nodes agree on the current state. This is linearizability, not the "C" in ACID (which means constraint enforcement).
  • Availability — every request receives a response (not an error), even if some nodes are down. The system keeps serving.
  • Partition tolerance — the system continues to operate when network messages between nodes are lost or delayed. In any real network, partitions happen.

Since partitions happen regardless of your design, every distributed system must be partition-tolerant. The theorem reduces to: during a partition, do you choose CP (consistent but unavailable) or AP (available but inconsistent)?

A CP system rejects requests it cannot guarantee are consistent. If a node is cut off from the leader, it returns an error rather than serve stale data. etcd, ZooKeeper, and HBase are CP. The system is correct but some requests fail during partitions.

An AP system continues to serve requests during a partition, accepting that different nodes may return different values. Cassandra and DynamoDB in their default configuration are AP. The system stays available but reads may be stale.

The CAP theorem is often oversimplified. In practice, partitions are rare and brief. Most of the time, a system provides all three properties. The trade-off only manifests during actual network failures. Modern systems like Spanner push the boundary by using synchronized clocks to minimize the consistency-availability trade-off.

Why it matters

CAP frames the fundamental design decision in distributed systems. When you choose a database or design a system, you need to know which property it sacrifices during failures — and whether your application can tolerate that sacrifice.

See How Consistency Works for real-world examples of CP and AP systems and how to choose between them.