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.

WriterWriterReplica 1Replica 1x = 1Replica 2Replica 2x = 1Replica 3Replica 3x = 1ReaderReader
  • Writer — healthy
  • Replica 1 — healthy — x = 1
  • Replica 2 — healthy — x = 1
  • Replica 3 — healthy — x = 1
  • Reader — healthy
  1. Three copies. The value x lives on 3 replicas, copies on separate machines, and each one says x = 1.
  2. The network splits. A split cuts off replica 3 and the reader, as a new write, x = 2, reaches replicas 1 and 2.
  3. Old answer, or none. A reader asking replica 3 can only get the old x = 1, or an error until the link heals.
  4. CAP is that choice. Answering keeps the system available, and refusing keeps it consistent; during a split, no system gets both.
  5. Wait for W copies. Once the link heals, a write can wait until W replicas have it; here W = 2 of N = 3.
  6. Ask R copies. A read of R = 2 replicas always reaches one with x = 2, since 4 > 3, and keeps the newer value.
  7. 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

  1. During a network split, a cut-off replica either answers with possibly old data or refuses.
  2. CAP stands for consistency, availability and partition tolerance; during a split, a system keeps only one of the first two.
  3. With N copies, a write waits for W of them and a read asks R of them.
  4. If W + R is more than N, every read reaches a copy with the latest write, and keeps the newest.

Go deeper in the CAP & consistency lab →

In plain words

Say the value x is stored on three replicas, and each one holds x = 1. The network splits, and 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 says no system can do both while the network is split. 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 , 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 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

Guided walkthroughOpen the full lab →
The choice this lab shows

Two regions each hold a copy of one balance. When the link between them breaks, called a partition, each region must choose.

  • CP: refuse writes until the link is back. Both copies stay the same, and users see errors.
  • AP: keep taking writes on both sides. Users see no errors, but the copies differ. When the link heals, one side's writes can be lost.
  • Read-Your-Writes is not a third CAP choice. It runs on top of AP, and sends your reads to the region that holds your own last write.

Step through one partition

Two regions hold one balance of $100. The link between them breaks, two users each make a deposit, and User 1 checks their balance. Pick a choice, then press Next step. Back takes you to the step before.

When a region is cut off

With this choice: Both deposits were taken, but User 1 read $120 without their own deposit. When the link came back, last-writer-wins kept $120 and lost the $50.

User 1, near US-EastUser 1near US-EastUser 2, near EU-WestUser 2near EU-WestUS-East, user:balance, NOWUS-Eastuser:balancecut offNOWEU-West, user:balanceEU-Westuser:balancecut off
  • User 1 — near US-East — healthy
  • User 2 — near EU-West — healthy
  • US-East — user:balance — healthy — NOW — cut off
  • EU-West — user:balance — healthy — cut off
  • Copy between regions
  • Deposit
  • Answer
Step 1 of 5

Step 1 of 5 · US-East

Failed: The link between the regions breaks

What happens
Both regions still run and still hold $100, but they cannot reach each other.
Why
This is a partition: the network splits, and each side keeps working alone.
What changes
Each region must now choose what to do with writes.
Next
US-East takes User 1's $50 deposit

Event log

4 more to go. Press a line to go back to that step.

US-East holds
$100
same as EU-West
EU-West holds
$100
same as US-East
The link
down
Watch: no copies cross

Step 1 of 5: US-East. The link between the regions breaks. Both regions still run and still hold $100, but they cannot reach each other.

What this simplifies. This run uses two regions, one key and a stated order of events. Real systems often use three or more sites, so a majority can keep taking writes. Many also merge both changes instead of dropping one.

Try it yourself

Press "Trigger Network Partition", make deposits in both regions, then press "Read my balance" and heal the link.

Choice:
Region A (US-East)
Primary Data Center
KEY: user:balance
$100
Version: v1
Region B (EU-West)
Secondary Data Center
KEY: user:balance
$100
Version: v1
Read your own balance

You made the deposits above. Your next read goes to the other region, as if your phone switched networks.

Replication & Consensus Log
No transactions recorded yet. Click deposit or trigger partition above.

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.

  1. 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.

  2. Availability

    Availability means every server that is still running answers each request, without an error. The answer may be old, but there is one.

  3. Partition tolerance

    A 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.

  4. The choice, and quorums (R + W > N)

    Pick a case to follow below

    With 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 xClientreads and writes xReplica 1, x = 1Replica 1x = 1Replica 2, x = 1Replica 2x = 1Replica 3, x = 1, FAILED, NOWReplica 3x = 1cut offFAILED
    • 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 3

    Step 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, 3
    1, 1, 1
    Replica 3 answers
    –
    not asked yet

    Step 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.

  5. PACELC: the cost when nothing is broken

    Pick a case to follow below

    With this case: Waiting for 1 replica took 1 ms, but the write was lost when replica 1 died.

    Client, reads and writes xClientreads and writes xReplica 1, x = 1, NOWReplica 1x = 1x = 2NOWReplica 2, x = 1Replica 2x = 1Replica 3, x = 1Replica 3x = 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 3

    Step 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 confirming
    1
    of 3 replicas
    Confirmed after
    –
    Copies of x = 2
    1
    If replica 1 then dies
    –
    not yet

    Step 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 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 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

During a network split, what does a CP system do when it cannot reach a majority of its copies?

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 . 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

PACELC adds a choice for when there is no network split. What is it?

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?

A database keeps N = 5 copies of each key and confirms a write after W = 3 copies have it. What is the smallest R that makes every read see the latest confirmed write?

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

A store keeps N = 3 copies. For fast writes you set W = 1. Using strict quorums, what R makes every read see the latest confirmed write?

Apply it

A shopping cart store chooses availability. During a partition, a user adds a book on one side and a pen on the other. What must happen when the link heals?

Judge a design

A bank ledger runs in 3 regions and must never show two different balances. The team wants every region to keep taking withdrawals during a partition. What is the problem?

Next: time, clocks and ordering, how replicas decide which write came last when their clocks disagree.

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.