The CAP Theorem

Why a distributed data store can only pick two of consistency, availability, and partition tolerance — and what that trade-off means in practice.

Beginner · 12 min read

Why this matters

Sooner or later you'll read an outage postmortem or a database marketing page that says something like "we chose availability over consistency during the incident." The CAP theorem is what gives that sentence meaning. It's the single most quoted idea in distributed systems — you'll hear it in interviews, design reviews, and conference talks. Half the people who mention it get it slightly wrong. (Not you. Not after this lesson.)

Video: My thoughts on the CAP theorem — Hussein Nasser
Hussein Nasser uses a master-and-replicas story to show how CAP trade-offs shape real architecture decisions.

Picture a restaurant chain

This lesson's running analogy: you run a tiny restaurant chain with two diners across town, sharing one menu. Let's define the CAP properties in diner terms:

And here's the thing about that phone line: it will get cut. Cables get chewed, switches die, packets vanish into the void. In the world of networks, the gremlins always strike eventually — usually at 2 a.m., usually right before your launch. A partition is simply two servers that are both alive, both serving customers, but unable to reach each other:

flowchart LR
    C[Client] --> R1[Replica 1]
    C --> R2[Replica 2]
    R1 -. "partition: the phone line is down" .-> R2

Video: CAP Theorem Simplified — ByteByteGo
Gaurav Sen explains each guarantee with simple visuals so the three CAP promises are easy to picture and compare.

The theorem, precisely

In the presence of a network partition, a distributed system must choose between consistency and availability. It cannot provide both.

Why? Go back to the diners. The phone line is cut. A customer at Diner 1 orders the new lunch special. Diner 2 has no idea the special changed — its menu board is stale. Now a customer at Diner 2 asks "what's the special?"

You have exactly two options, and they are both a little awkward:

  1. Diner 2 answers with the old special (stale data) — that's availability: everyone gets served, but not everyone gets the truth.
  2. Diner 2 refuses to answer until it can confirm the menu — that's consistency: no one gets a wrong answer, but someone gets no answer at all.

There is no third option where the diner serves the correct special without talking to Diner 1. That's the whole theorem. It's less a deep mathematical mystery and more a very obvious dilemma — dressed up in academic clothes.

flowchart TD
    P{Phone line cut?} -->|No| CA[Consistent AND available]
    P -->|Yes| CH{What's the priority?}
    CH -->|The truth matters most| CP[CP: refuse unsafe requests]
    CH -->|Serving customers matters most| AP[AP: keep serving, maybe stale]

Because partitions are inevitable, the "P" in CAP is really non-negotiable for a distributed system — so the practical question is: during a partition, are you CP or AP?

ChoiceDuring a partitionExample systems
CPReject or block requests it can't guarantee are consistentZooKeeper, etcd, HBase
APKeep serving requests, possibly with stale or conflicting dataCassandra, DynamoDB, Riak

A CP system would rather close the kitchen than serve the wrong special:

sequenceDiagram
    participant Client
    participant NodeA as Reachable Node
    participant NodeB as Unreachable Node

    Client->>NodeA: Write request
    NodeA--xNodeB: Replicate write
    Note over NodeA,NodeB: Partition — the other node can't be reached
    NodeA-->>Client: Reject write (better no answer than a wrong one)

Video: CAP Theorem Explained in 6 Minutes | System Design Interview #11 — Learn with Manoj
Defines consistency, availability, and partition tolerance exactly, then states the real tradeoff clearly.

The thing everyone gets wrong

Here is the misconception to watch for at parties: CAP does not say a system must permanently pick only two of three, like some kind of loyalty program. When the phone line is working — which is most of the time — a system can be both consistent and available. The trade-off only bites during a partition. It's a fire-escape plan, not a personality type.

This is also why later models like PACELC extended CAP: they ask "and even when there's no partition, are you trading consistency for latency?" Because the gremlins are always in the details.

Video: Why Are Distributed Systems so Hard? • Denise Yu • GOTO 2020 — GOTO Conferences
Conference talk clearing up CAP myths, like why partition tolerance is never optional.

Takeaways

  1. Partitions are a fact of life, not an edge case — the gremlins always strike eventually, so design for them explicitly.
  2. During a partition you must choose: serve everyone with possibly stale data (AP), or serve only what you can guarantee is correct (CP).
  3. CAP's C means linearizability — every read sees the latest completed write, as if there were only one copy — which is a different idea from ACID's C (transactions preserve your data's rules). Same word, different meaning entirely.
  4. Most real systems are tunable (e.g., Cassandra's quorum reads/writes) rather than strictly CP or AP — CAP is a lens for reasoning, not a rigid checklist.

Check your understanding

  1. The phone line between your two diners is cut. A CP system will...

    • Keep seating customers and serving whatever's on the board, stale or not
    • Shut down both diners permanently rather than risk a wrong answer
    • Invent new specials on the spot and hope for the best
    • Refuse requests it can't guarantee are correct until it can reach the other diner
  2. What is a 'partition' in the context of the CAP theorem?

    • Two nodes that are both alive and reachable by clients, but unable to reach each other
    • A logical division of a database's rows across its servers
    • A firewall rule that blocks all client traffic to the cluster
    • A scheduled maintenance window during off-peak hours
  3. When there is NO network partition, a distributed system can be...

    • Only consistent, never available
    • Only available, never consistent
    • Both consistent and available at the same time
    • Neither — the theorem forbids it
  4. Which of these is an example of an AP system, as described in the lesson?

    • ZooKeeper
    • Cassandra
    • etcd
    • HBase

Go deeper

Want to keep pulling this thread? These talks and tutorials go further than we did here:

Sources & further reading