2026-07-11 · System Atlas
The CAP Theorem Explained Simply
If you are building distributed systems or preparing for a system design interview, you will inevitably encounter the CAP Theorem.
Coined by computer scientist Eric Brewer in 2000 (and formally proven by Gilbert and Lynch in 2002), the CAP theorem states a fundamental limitation of distributed data stores: any distributed system can only guarantee two out of the following three properties at the same time:
- Consistency (C)
- Availability (A)
- Partition Tolerance (P)
Let's break down exactly what these mean without the academic jargon — and, more importantly, how to reason about them the way an interviewer expects you to.
Want to feel this instead of reading about it? Open the interactive CAP theorem simulation — cut the network between two replicas yourself and watch what happens to reads and writes under CP vs AP. It's free and runs in your browser.
1. Consistency (C)
Consistency means that every read receives the most recent write, or an error.
If you update your profile picture and then immediately refresh the page, you should see the new picture. If another user on a different continent loads your profile, they should also see the new picture. All nodes in the system see the exact same data at the same time.
A subtle but important point for interviews: this is linearizability, not the "C" in ACID. The ACID "C" is about database invariants (e.g., a transfer never creates or destroys money). The CAP "C" is about replicas agreeing on the latest value. Interviewers love candidates who make this distinction unprompted.
2. Availability (A)
Availability means that every request receives a (non-error) response, without the guarantee that it contains the most recent write.
If a user requests data, the system will always send something back, even if one or more servers are currently down or unreachable. Note that CAP availability is a strong claim — every non-failing node must respond — which is stricter than the "four nines" operational availability you discuss in capacity planning.
3. Partition Tolerance (P)
A partition is a communications break within a distributed system — a lost or temporarily delayed connection between two nodes.
Partition Tolerance means that the system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes.
The Reality: You Must Choose 'P'
In the real world, network failures will happen. Cables get cut, switches fail, routers misbehave, garbage collection pauses make healthy nodes look dead, and packets drop. Therefore, any distributed system running over a network must be Partition Tolerant (P).
This is the single most common CAP misconception: "CA systems" don't meaningfully exist in a distributed setting. A single-node PostgreSQL instance is CA in a trivial sense — but the moment you add a replica across a network, you've signed up for partitions.
Because 'P' is mandatory, the CAP theorem really means: when a network partition occurs, you must choose between Consistency (C) and Availability (A).
Option 1: CP (Consistency + Partition Tolerance)
When a network partition happens, a CP system will refuse to respond (or return an error) to some requests to ensure that no stale data is ever returned.
- Use case: Financial systems, inventory counts, anything where two users acting on stale data causes real damage. You'd rather the ATM say "Service Unavailable" than show an incorrect bank balance.
- Examples: ZooKeeper and etcd (consensus-based), HBase, MongoDB in its default configuration (writes go through a primary; a partitioned primary steps down).
Option 2: AP (Availability + Partition Tolerance)
When a network partition happens, an AP system will always respond to requests, even if that means returning stale data — and reconciling conflicting writes after the partition heals.
- Use case: Social media feeds, product views, shopping carts. It's fine if you see a post a few seconds later than someone else, as long as the app keeps loading.
- Examples: Cassandra, DynamoDB, CouchDB, DNS (arguably the largest AP system in existence).
A Worked Failure Scenario
Abstract definitions don't stick. Walk through this concrete scenario — it's also a great structure to narrate in an interview.
Imagine a two-datacenter deployment: Node A in Virginia, Node B in Frankfurt. Both hold a copy of user balances. The transatlantic link fails. Now:
- A client in Europe asks Node B: "What is Alice's balance?"
- Node B cannot reach Node A, so it cannot know whether Alice's balance changed in Virginia a millisecond ago.
- Node B has exactly two options:
- Answer anyway with its local (possibly stale) copy → the system stays available but may be inconsistent (AP).
- Refuse to answer until it can confirm with Node A → the system stays consistent but is unavailable for that request (CP).
There is no third option. That's the whole theorem. Everything else — quorums, leader election, hinted handoff, vector clocks — is engineering to make one of these two choices less painful.
Now run the same scenario with a write: a European client asks Node B to set Alice's balance. An AP system accepts the write locally and syncs later (risking a conflict with a concurrent write in Virginia). A CP system rejects the write because it can't replicate it. This is why AP systems need conflict resolution strategies — last-writer-wins, CRDTs, or application-level merges like Amazon's famous shopping cart.
Try exactly this experiment in the CAP simulation: trigger a partition, issue writes on both sides, and watch the conflict surface when the network heals.
Beyond CAP: PACELC
CAP only describes behavior during a partition. But partitions are rare — what about the other 99.9% of the time? That's what PACELC (pronounced "pass-elk") adds:
If there is a Partition, choose between Availability and Consistency; Else, choose between Latency and Consistency.
Even on a healthy network, strong consistency costs latency: a strongly consistent read may need to contact a quorum of replicas (possibly across continents), while an eventually consistent read can be served by the nearest replica immediately.
- PA/EL (give up consistency in both cases for speed and uptime): Cassandra, DynamoDB with eventually consistent reads.
- PC/EC (consistency first, always): ZooKeeper, etcd, spanner-style systems (Google Spanner pays the latency cost with atomic clocks and careful engineering).
- PA/EC and PC/EL hybrids also exist — MongoDB is commonly classified PA/EC.
Mentioning PACELC — briefly and correctly — is one of the highest-signal moves available in a system design interview, because it shows you understand consistency as a spectrum with costs, not a checkbox.
Tunable Consistency: The Modern Reality
Modern databases rarely force a single global choice. They expose knobs:
- Cassandra / DynamoDB style quorums: with
Nreplicas, you choose how many must acknowledge a write (W) and how many must answer a read (R). IfR + W > N, reads see the latest write (consistent, slower). IfR + W ≤ N, you've chosen speed over freshness.N=3, W=2, R=2is the classic balanced configuration. - MongoDB: write concerns (
w: majorityvsw: 1) and read preferences (primary vs secondary) let you pick per-operation. - DynamoDB: a literal
ConsistentRead: trueflag — strongly consistent reads cost twice as much as eventually consistent ones. AWS charging double for consistency is the CAP theorem expressed as a pricing table.
The practical skill isn't memorizing which database is "CP" or "AP" — it's knowing that consistency is chosen per operation, based on what the business can tolerate.
How to Use CAP in a System Design Interview
Don't recite the theorem. Apply it. A strong pattern:
- Identify the data: "We have two kinds of data here: payment records and the activity feed."
- Assign requirements: "Payments need strong consistency — a double-charge is unacceptable. The feed can be eventually consistent — nobody notices a 2-second delay."
- Pick storage accordingly: "So I'd put payments in a strongly consistent store and serve the feed from a replicated, eventually consistent one."
- Name the failure behavior: "During a partition, payment writes in the minority partition will fail and we'll surface a retry — that's the CP trade we're accepting."
That's 30 seconds of speech, and it demonstrates more understanding than five minutes of definitions. Interviewers are listening for the phrase pattern "during a partition, this system will ___ because we chose ___."
Common mistakes to avoid
- Claiming a system is "CA" — in a distributed setting this signals you haven't internalized that partitions aren't optional.
- Treating consistency as binary — real systems offer levels (linearizable, sequential, causal, eventual).
- Forgetting that CAP applies per data item / per operation, not once per company.
- Confusing CAP consistency with ACID consistency.
Summary
The CAP theorem is a crucial mental model for understanding database tradeoffs:
- Partitions are a fact of life — P is not optional in distributed systems.
- During a partition you choose: refuse requests (CP) or serve possibly-stale data (AP).
- Outside partitions, PACELC says you're still trading latency vs consistency.
- Modern databases make this a per-operation knob, not a religion.
When choosing a database for your next project, ask yourself: "If the network fails, is it more important to be correct (CP), or to stay online (AP)?" — and be ready to answer it separately for every type of data you store.
Go further:
- 🧪 Play with the interactive CAP theorem simulation — free, no account needed.
- 📖 Read the deep-dive guide chapter on Consistency vs Availability.
- 📖 Understand replication strategies — where these tradeoffs get implemented.