Stage 3 · Distributed data · Hard · 20 min
CAP, PACELC and quorums
What a database can promise when its machines cannot reach each other. Learn the CAP choice, its everyday cost (PACELC), and how read and write quorums overlap.
What each interview level is expected to know
Learn first: Replication and sharding
After this lesson you can:
- Explain the choice between consistency and availability during a network split.
- Use R + W > N to check whether reads will see the latest write.
- Explain the latency cost PACELC adds when nothing is broken.
Start here
See it in 60 seconds
Old data, no answer, or a quorum
When the network splits, a replica must answer with possibly old data or refuse; without a split, overlapping read and write quorums keep reads fresh.
Scene 1 of 6 · Three copies
The value x lives on 3 replicas, copies on separate machines, and each one says x = 1.
- Writer — healthy
- Replica 1 — healthy — x = 1
- Replica 2 — healthy — x = 1
- Replica 3 — healthy — x = 1
- Reader — healthy
- Three copies. The value x lives on 3 replicas, copies on separate machines, and each one says x = 1.
- The network splits. A split cuts off replica 3 and the reader, as a new write, x = 2, reaches replicas 1 and 2.
- Old answer, or none. A reader asking replica 3 can only get the old x = 1, or an error until the link heals.
- CAP is that choice. Answering keeps the system available, and refusing keeps it consistent; during a split, no system gets both.
- Wait for W copies. Once the link heals, a write can wait until W replicas have it; here W = 2 of N = 3.
- Ask R copies. A read of R = 2 replicas always reaches one with x = 2, since 4 > 3, and keeps the newer value.
- Now you try. Pick how many of the 3 replicas a write waits for (W) and a read asks (R). For example: W + R = 3, not more than 3, so the read can miss every replica with x = 2 and see the old x = 1. The read may land only on replicas the write has not reached yet, so it returns old data.
Scene 1 of 6: Three copies. The value x lives on 3 replicas, copies on separate machines, and each one says x = 1.
Key points
- During a network split, a cut-off replica either answers with possibly old data or refuses.
- CAP stands for consistency, availability and partition tolerance; during a split, a system keeps only one of the first two.
- With N copies, a write waits for W of them and a read asks R of them.
- If W + R is more than N, every read reaches a copy with the latest write, and keeps the newest.
In plain words
Say the value x is stored on three replicas, and each one holds x = 1. The network splits, and (A copy of a database kept on another machine.) 3 is cut off. Then a write sets x = 2, but only replicas 1 and 2 receive it. Now a reader asks replica 3. It can reply x = 1, which is out of date, or refuse until the link is back. If it replies, the system stays available. If it refuses, the system stays consistent. The (When copies of data cannot reach each other, a system must choose. It can refuse some requests and stay consistent, or answer them and risk old data. CAP stands for consistency, availability and partition tolerance.) says no system can do both while the network is split. (An extension of CAP. If there is a partition (P), choose availability or consistency (A or C). Else (E), when all is well, choose lower latency or consistency (L or C).) adds the normal case: with no split, waiting for more replicas gives fresher answers but slower ones.
So during a split, a cut-off replica follows a rule chosen in advance. A CP system, which keeps consistency, has replica 3 refuse reads and writes until it hears from the others again. An AP system, which keeps (In the CAP theorem: every server that is still running answers each request without an error, even if the answer is old.), lets it answer, and settles any disagreement once the link is back, for example by keeping the newest write. Some databases, such as Cassandra, let you choose for each request, by how many replicas must answer.
The problem it solves
Replicas stay the same only by sending each other every write. When those messages cannot get through, a replica does not know what it has missed. Any answer it gives may be out of date, and any write it accepts may clash with a write on the other side.
Why it matters
Any system that keeps copies of data on several machines must plan for the day those machines cannot reach each other. A cable is cut, a switch fails, or a link is overloaded. CAP says what the system can still promise while that lasts. Interviewers ask what a user sees during that time, not what the letters stand for.
A worked example
A store keeps N = 3 copies of each record. Writes must reach W = 2 replicas before they succeed. Reads must then check at least R = 2 replicas to overlap with the write, since 2 + 2 = 4 is greater than 3. Checking only R = 1 would risk missing the latest write, since 1 + 2 = 3 is not greater than 3. That overlap is what a (The smallest group of machines that must agree, usually more than half.) read relies on.
Think of it like…
Think of two food trucks at a fair that share one tally of a limited dish. A runner carries each sale between them. If the crowd blocks the runner, each truck must decide alone: keep selling and risk selling too many, or stop.
Where this analogy stops working
The forced choice is the useful part. But a truck can see that the runner is blocked. A machine cannot: a broken link, a slow peer and a crashed peer all look like silence. Real systems also choose for each feature, not once for the whole product.
Try it
See it working
Also try: Replication
Mechanics
How it works
The pictures follow this page's example: the value x on three replicas. The first shows the choice during a network split. The second shows the cost that remains when nothing is broken.
Consistency
In CAP, consistency means every read returns the newest write. It is as if there were only one copy of the data. This strict meaning is also called linearizability.
Availability
Availability means every server that is still running answers each request, without an error. The answer may be old, but there is one.
Partition tolerance
A (In the CAP theorem, short for network partition: a broken link that splits servers into groups that cannot reach each other.) is a break in the network that stops some servers from reaching others. The servers are fine, but messages between them are lost. Partitions can happen on any real network, so a design must have a plan for them.
The choice, and quorums (R + W > N)
Pick a case to follow belowWith this case: Choosing availability, replica 3 answered x = 1, an out-of-date value. The system stayed up but was not consistent.
Client, reads and writes x Client reads and writes x Replica 1, x = 1 Replica 1 x = 1 Replica 2, x = 1 Replica 2 x = 1 Replica 3, x = 1, FAILED, NOW Replica 3 x = 1 cut off FAILED - Client — reads and writes x — healthy
- Replica 1 — x = 1 — healthy
- Replica 2 — x = 1 — healthy
- Replica 3 — x = 1 — FAILED — NOW — cut off
- Lost or refused
- Request
- Answer
Step 1 of 3Step 1 of 3 · Replica 3
Failed: The network splits
- What happens
- Replica 3 can no longer reach replicas 1 and 2. All three servers are still running.
- Why
- A partition breaks the links, not the servers, so each side carries on alone.
- What changes
- Each replica still holds x = 1.
- Next
- A write sets x = 2 on replicas 1 and 2
x on replicas 1, 2, 31, 1, 1Replica 3 answers–not asked yetStep 1 of 3: Replica 3. The network splits. Replica 3 can no longer reach replicas 1 and 2. All three servers are still running.
During a partition a replica that cannot reach the others has two options. It can refuse requests and stay consistent (CP), or answer with what it has and stay available (AP). Quorums tune this. With N = 3 copies, writing to W = 2 and reading from R = 2 gives R + W > N. With strict quorums, every read then reaches at least one copy that has the newest confirmed write.
In the picture, replica 3 is cut off, and then a write sets x = 2 on the other two. Pick the first case: replica 3 answers x = 1, which is out of date. Pick the second: it refuses, and the reader gets an error but never a wrong value.
Neither answer is free. A shopping cart might prefer to stay available and fix small mistakes later. A bank balance usually prefers to refuse.
PACELC: the cost when nothing is broken
Pick a case to follow belowWith this case: Waiting for 1 replica took 1 ms, but the write was lost when replica 1 died.
Client, reads and writes x Client reads and writes x Replica 1, x = 1, NOW Replica 1 x = 1 x = 2 NOW Replica 2, x = 1 Replica 2 x = 1 Replica 3, x = 1 Replica 3 x = 1 - Client — reads and writes x — healthy
- Replica 1 — x = 1 — healthy — NOW — x = 2
- Replica 2 — x = 1 — healthy
- Replica 3 — x = 1 — healthy
- Request
- Answer
Step 1 of 3Step 1 of 3 · Replica 1
Done: Replica 1 stores x = 2
- What happens
- The client sends the write to replica 1, which stores it in 1 ms.
- Why
- Nothing is broken, so every link works.
- What changes
- That is enough copies for this setting.
- Next
- The write is confirmed at 1 ms
Copies before confirming1of 3 replicasConfirmed after–Copies of x = 21If replica 1 then dies–not yetStep 1 of 3: Replica 1. Replica 1 stores x = 2. The client sends the write to replica 1, which stores it in 1 ms.
What these pictures simplify. These pictures use three replicas, one value and round times: 1 ms for the first replica and 5 ms to wait for a second. Real systems tune these settings per request. The CAP lab above splits two regions and lets you send your own writes.
PACELC reads: if there is a Partition, choose Availability or Consistency; Else, choose (How long one request takes, from sending it to getting the answer.) or Consistency. The second half is the everyday case. A write that waits for 2 of 3 replicas is safer than one that waits for 1. It is also slower, because it must wait for a second replica to answer.
In the picture, nothing is broken. Waiting for 1 replica confirms the write in 1 ms, but if that replica dies right after, the write is gone. Waiting for 2 of 3 takes 5 ms, and the write survives. These are round example times.
Use it when
- Choose consistency (CP) when a wrong answer costs more than no answer, such as a seat booking or a stock count. The user sees an error during the partition and (A tree that stores words one letter per step, so words that start the same share a path.) again later.
- Choose availability (AP) when a slightly old answer does no harm, such as a like count or a feed. The replicas catch up once the partition ends.
- Use quorums to set the balance per request. With N = 3, W = 2 and R = 2 keep reads fresh and still work with one replica down.
Skip it when
- Do not call a distributed system "CA", consistent and available: that describes a network that never splits, and no real network can promise that.
- Do not label a whole product CP or AP: the choice is made per feature. Checkout can refuse while the like counter keeps answering.
- A single database on one machine: there is no second copy to disagree with, so CAP has nothing to say about it.
Check yourself
Judgement
Trade-offs and how it fails
What you give up
- Consistency
- To keep every read up to date, a write must wait until enough replicas have it. That adds a network round trip to each write. During a partition, the side that is cut off must refuse requests.
- Availability
- A replica that accepts writes on its own keeps answering through a partition. The replicas then disagree for a while, and agree again after they sync. This is called (Copies of the data may differ for a short time after a write, but they all reach the same value once writes stop.). Two writes to the same key must be merged, or one of them is dropped.
Failure modes
- Conflicting writes: during a partition both sides accept a change to the same record. When the link heals there are two versions. Without a merge rule, one of them is lost and nobody is told.
- No quorum: a CP system that cannot reach a majority of its replicas refuses every write. Users on the smaller side of the partition see errors until the link heals.
- A quorum that does not overlap: N = 3, W = 1 and R = 1. A read can land on a replica the write has not reached, because R + W is 2, not more than 3.
- A stand-in replica: when a replica is down, some stores write to another machine for now. This is called a sloppy quorum. A read of the usual replicas can then miss that write, even when R + W is more than N.
In the real world
- Google's Spanner paper (2012) describes TrueTime, a clock service built on GPS and atomic clocks. Spanner uses it to put writes in one agreed order across data centres. Source: Google: the Spanner paper (2012) (checked 14 October 2026)
- Cassandra's documentation lets each query set its own consistency level, such as ONE, QUORUM or ALL.
- Amazon's Dynamo paper (2007) describes a shopping cart store that accepts writes during a partition. It merges the differing carts afterwards. Source: Amazon: the Dynamo paper (2007) (checked 14 October 2026)
- Eric Brewer, who proposed CAP, wrote in 2012 that the "2 of 3" wording was always misleading. He said the choice between consistency and availability can be made many times within one system. Source: Eric Brewer, "CAP Twelve Years Later" (2012) (checked 14 October 2026)
Trade-offs to be ready to discuss: Cp vs ap systems · Strong vs eventual consistency
Check yourself
Interview
What interviewers look for
- Do not say "my system is CA". A design cannot opt out of partitions, so the real choice is what to do when one happens: refuse (CP) or answer (AP).
- Add the normal case with PACELC: "With no partition I still choose. A quorum write is safer and slower than a write to one replica."
- Do not recite the three letters. Say what a user sees during a partition: "Checkout shows an error and stays correct. The like counter keeps working and catches up later."
- Show the quorum sum: "N = 3, W = 2, R = 2. R + W is 4, more than 3, so every read reaches a replica with the latest write."
Say it out loud: Why is "CA", consistent and available, not a real choice for a distributed system?
Expected depth by interview level
Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.
- JuniorBeyond this level
- Knowing what the term means is enough.
- MidExpected
- What each side of a partition returns, for a concrete feature.
- SeniorCore
- Consistency choices per feature, and the PACELC latency trade-off.
- StaffCore
- Consistency models across a system, and their cost.
Practice
Apply it
Three harder questions
The first two use the idea on a new case. The last asks you to judge a design.
Apply it
Apply it
Judge a design
Go deeper
Sources and further reading
First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.
- Research paperBrewer’s Conjecture and the Feasibility of Consistent, Available, Partition-Tolerant Web Services (2002)Gilbert and Lynch, ACM SIGACT NewsThe formal proof of CAP, with exact meanings for consistent and available.
- Research paperConsistency Tradeoffs in Modern Distributed Database System Design (2012)Daniel Abadi, IEEE ComputerWhere PACELC comes from: even with no partition, you trade latency against consistency.
- Engineering guideCAP Twelve Years Later: How the “Rules” Have ChangedEric Brewer, InfoQ / IEEE ComputerThe author of CAP on why “pick two of three” misleads.