Skip to content
learn
  1. Learn
  2. High Level System Design
  3. Distributed Systems Theory

System Design HLD-08.02

CAP theorem, properly explained

What consistency, availability and partition tolerance really mean, why partitions are not optional, how CP and AP systems behave, and common misreadings.

Intermediate 12 min Last reviewed

The big idea

The CAP theorem is the most quoted and most misquoted result in system design. It is usually summarized as "consistency, availability, partition tolerance: pick two", which sounds like a menu where you could skip partitions. You cannot. Networks partition: links fail, switches reboot, a data center loses its connection. So the real statement is narrower and more useful: when a network partition happens, a replicated system must choose between consistency and availability for the duration of the partition.

Either it refuses some requests so that nobody ever reads stale or conflicting data (CP), or it keeps answering every request and accepts that the two sides may disagree until the partition heals (AP). When there is no partition, a well-built system can be both consistent and available.

Think of two bank branches whose phone line goes down. Either they stop allowing withdrawals until they can talk again (consistent, not available), or they keep paying out and sort out any overdrafts afterwards (available, not consistent).

How it works

Step 1: The three letters, precisely

  • Consistency (C) in CAP means linearizabilityEvery operation appears to take effect at a single instant; once a write completes, every later read, from any client, sees it. Behaves like a single copy.: the system behaves as if there were a single copy of the data. Once a write is acknowledged, every read anywhere returns it. (This is not the C in ACID.)
  • Availability (A) means every request to a non-failed node gets a non-error response, eventually.
  • Partition tolerance (P) means the system continues to operate even though the network drops or delays messages between nodes.

Step 2: During a partition

A network partition forces a choice between consistency and availability Two data centers lose the link between them, shown flickering red. On the CP side, the minority data center refuses writes and returns errors to stay consistent. On the AP side, both data centers keep accepting writes, and their values diverge until the link heals and they reconcile. CP choice AP choice cut cut DC 1 majority: serves DC 2 minority: errors DC 1 x = v2 DC 2 x = v3 never wrong, sometimes unavailable always answers, sometimes stale Figure 1. The link between data centers is cut (red). A CP system refuses requests on the side that cannot reach a majority; an AP system answers everywhere and lets the copies diverge, reconciling later.
  • A CP system, such as etcd, ZooKeeper or a consensus-based database, lets only the side with a majority of replicas serve requests. The minority side returns errors or times out. Nobody ever sees inconsistent data, but some users get errors.
  • An AP system, such as Cassandra or DynamoDB in their default modes, or a DNS cache, lets every node keep serving. Writes on both sides succeed and the copies diverge; when the partition heals they must reconcile, often with last-write-wins or merges ( Multi-leader and leaderless replication ).

Try it

This interactive needs JavaScript. The diagrams and text above cover the same idea.

Try this:

  1. In CP mode, cut the link, then write from DC 2. It is refused. Write from DC 1: accepted, because DC 1 holds a majority.
  2. Switch to AP, cut the link, and write different values from both sides. Read from each: they disagree.
  3. Heal the link. Last write wins, and the other side's write silently disappears. Was that acceptable for this data?

Going deeper

Common misreadings

  • "Pick two." You do not get to drop P; partitions happen. The choice only exists during one.
  • "CA systems." A single-node database is "CA" only because it has no partitions to tolerate; the moment you replicate it, CAP applies.
  • "NoSQL is AP, SQL is CP." Many databases let you choose per operation (quorum settings, read concerns), and the same system can behave either way.
  • "Consistent means ACID." CAP's C is linearizability of a single object, a different idea from transactional consistency.

Partitions are rare, latency is constant

CAP says nothing about normal operation, where the real everyday trade-off is between latency and consistency. That is what PACELC adds, in PACELC and consistency models .

Trade-offs

OptionWins whenLoses when
CP behavior Locks, leader election, configuration, money, inventory: data that must never be wrong Availability on the minority side during partitions
AP behavior Shopping carts, feeds, counters, caches, DNS: answering beats being exact Consistency: conflicts must be resolved later, sometimes losing writes
Tunable per operation Systems with both kinds of data Simplicity: every call needs the right setting

Common mistakes

  • Treating CAP as a permanent three-way choice rather than behavior during a partition.
  • Choosing AP without a plan for reconciling divergent writes.
  • Claiming a replicated system is "CA".
  • Ignoring the latency cost of consistency in normal operation, which matters far more often.

Check yourself

  1. What does CAP actually force you to choose?

    Show answer

    B. Between consistency and availability while a network partition is happening Partitions are unavoidable; during one, a replicated system cannot be both linearizable and fully available.

  2. In a CP system with replicas split 2 and 1, what happens on the side with 1 replica during a partition?

    Show answer

    B. It refuses requests it cannot confirm with a majority Without a majority it cannot guarantee it has the latest value, so it returns errors.

  3. What does C mean in CAP?

    Show answer

    B. Linearizability: the system behaves like a single copy Once a write is acknowledged, every subsequent read anywhere sees it.

  4. Which data is best served by an AP approach?

    Show answer

    C. A shopping cart or like counter Staying available matters more than momentary exactness, and conflicts can be merged.

Recap

  • Partitions happen; CAP is about behavior while one is in progress.
  • C means linearizable, A means every non-failed node answers, P means surviving lost messages.
  • CP refuses requests on the minority side; AP answers everywhere and reconciles later.
  • Many systems let you choose per operation or per dataset.
  • In normal operation the trade-off is latency versus consistency: see PACELC.

Get new lessons by email

Get new posts on backend and AI internals. No spam, unsubscribe anytime.

Your email is only used to send new posts. Privacy

Next up