Building Blocks · Consistency and Availability

CAP, Consistency Models and Quorums

What a network partition forces you to choose, strong versus eventual consistency, quorum reads and writes, and PACELC's latency trade-off.

  • 11 min read
  • 11 practice questions
On this page
  1. Description
  2. CAP in plain words
  3. The everyday trade-off: PACELC
  4. Consistency models, from strongest to weakest
  5. Quorums: overlapping reads and writes
  6. When copies disagree
  7. Which to use when
  8. Common mistakes
  9. Check yourself
  10. Key takeaways
  11. Quick revise
  12. Practice

Description

Whenever a system keeps copies of its data on more than one machine, it has to decide what happens when those copies can't talk to each other - and what "up to date" means the rest of the time. This lesson is about that decision: the CAP theorem, the consistency models you can choose from, and the quorum arithmetic behind many databases.

Picture a concert-ticket site that keeps its seat data in two data centers, one in Virginia and one in Dublin. One evening the link between them drops for 90 seconds. Two fans, one on each side of the Atlantic, click "Buy" on seat 14C at the same moment.

The site has two honest options:

  • Let both purchases go through. Both fans get a confirmation email, and you've sold one seat twice. Someone gets turned away at the door.
  • Refuse sales on one side until the link is back. Fans there see an error page for a minute and a half.

There's no third option that keeps every request working and never double-sells. That trade-off has a name, the CAP theorem, and every system that keeps copies of its data on more than one machine runs into it. You either choose how to handle it, or you find out what you chose during an outage.

Fan in BerlinDublin copyVirginia copyFan in AustinFan in BerlinDublin copyVirginia copyFan in AustinThe link between the data centers is downChoice 1 (available): both say yes, and the seat is sold twiceChoice 2 (consistent): one side says "try again later"Buy seat 14CBuy seat 14C
Fan in BerlinDublin copyVirginia copyFan in AustinFan in BerlinDublin copyVirginia copyFan in AustinThe link between the data centers is downChoice 1 (available): both say yes, and the seat is sold twiceChoice 2 (consistent): one side says "try again later"Buy seat 14CBuy seat 14C

In this lesson:

  1. CAP in plain words, and why "pick two" is misleading.
  2. PACELC - the trade-off you pay on every request, not just during outages.
  3. Consistency models, from strongest to weakest, and matching them to features.
  4. Quorums: when reads are guaranteed to see the latest write.
  5. What to do when copies disagree.

CAP in plain words

CAP talks about three properties of a system that keeps copies (replicas) of its data on different machines:

  • Consistency (C): every read sees the most recent write, as if there were only one copy. The formal name is linearizability.
  • Availability (A): every request that reaches a working machine gets a real answer, not an error.
  • Partition tolerance (P): the system keeps running when the network splits it into groups that can't talk to each other.

You'll often hear "pick two of the three". That's misleading. Networks do split: cables get cut, switches fail, a cloud region has a bad day. So partition tolerance isn't something you get to skip. The real question is what your system does during a split:

  • CP (consistent): refuse or delay the requests it can't answer safely. etcd, ZooKeeper, and a single-leader database that rejects writes on the side without the leader all work this way.
  • AP (available): answer from whatever copy it can reach, and sort out disagreements later. Cassandra and DynamoDB behave this way in their default settings.
Read more - what about "CA" systems?

A "CA" system is one that can't survive a network split, which really means it isn't distributed: a single database server, for example. It's consistent and available right up until its one machine or its network fails. That's a perfectly good design for many products, but it's not an answer to the CAP question.

The everyday trade-off: PACELC

Network splits are rare. Latency is with you on every single request. PACELC adds that second half: if there's a Partition, choose Availability or Consistency; Else, choose Latency or Consistency.

Here's why. To be strongly consistent, a write has to reach a majority of copies before you tell the user "saved". If those copies live in different regions, that's a round trip across an ocean on every write. Most databases therefore let you choose per request. A checkout can pay for a strongly consistent read of the stock count. A product page can show a count that's a second old.

Consistency models, from strongest to weakest

ModelWhat it promisesGood for
Linearizable (strong)Every read sees the latest writeUnique usernames, seat reservations, account balances, locks
CausalIf one write caused another, everyone sees them in that orderComments and the replies to them
Read-your-writes, monotonic readsYou see your own changes, and you never jump back in timeEditing your profile, your own posts
EventualCopies agree once writes stopLike counts, view counters, recommendations

The key skill is matching the model to the feature, not to the whole system. One social app can keep usernames strongly consistent and like counts eventually consistent, side by side. Paying for strong consistency everywhere makes everything slower. Skipping it where it matters double-sells seats.

Read more - read-your-writes in practice

A common way to give users read-your-writes on top of lagging read replicas: for a few seconds after a user changes something, send that user's reads to the leader (or to a replica that has caught up past their write). Everyone else keeps reading from replicas. The user never sees their own edit vanish, and the leader isn't flooded.

Quorums: overlapping reads and writes

Many replicated stores keep each item on N machines. A write counts as done once W of them confirm it. A read asks R of them and keeps the newest version it gets back.

The rule to remember: if R + W > N, every read overlaps every acknowledged write in at least one machine. That overlapping machine has the latest value, so the read sees it.

N = 3 copies of one item

the overlap: has the latest write

Copy 1

Copy 2

Copy 3

Write, W = 2

Read, R = 2

N = 3 copies of one item

the overlap: has the latest write

Copy 1

Copy 2

Copy 3

Write, W = 2

Read, R = 2

For N = 3:

WRR + W > N?What you get
22YesBalanced. Reads and writes both survive one copy being down
31YesFast reads, but if any copy is down, writes stop
13YesFast writes, but if any copy is down, reads stop
11NoFastest, and reads may be stale

Quorums make stale reads much rarer, but they don't make a system linearizable on their own: two writes can race, and some stores accept writes on stand-in machines during failures. When you truly need "only one person gets seat 14C", use a store built on a consensus protocol such as Raft, which runs every write through an elected leader and a majority vote.

When copies disagree

In an AP system, two copies can accept different writes for the same item during a split, or two users can edit the same record at the same moment. Something has to decide what the final value is.

  • Last write wins (LWW): keep the write with the later timestamp. It's simple, and it silently throws the other write away. Server clocks drift, so it can even throw away the write that really came last.
  • Keep both and merge: store versions (vector clocks) and merge them in the application, the way a shopping cart can combine items added on two devices.
  • Use data types that merge themselves (CRDTs): counters, sets and similar structures designed so that any two copies combine to the same answer.
  • Avoid the conflict: send all writes for one item to a single leader, so there's never more than one opinion.

Which to use when

SituationReach for
Money, inventory, unique names, locksA strongly consistent store (single leader with synchronous replication, or a consensus-based store)
A user must see their own change immediatelyRead-your-writes: read from the leader for that user for a short while
Counters, likes, views, analyticsEventual consistency, ideally with CRDT counters
Global users, writes from many regionsAn AP store with conflict resolution, or a leader per item (home region)
An interview question that says "highly available"Say what is allowed to be stale and for how long, then pick the model per feature

Common mistakes

  • "We'll pick CA." Not an option for a distributed system: say what happens during a split instead.
  • Strong consistency everywhere. It costs latency on every request and availability during failures. Use it where a stale answer breaks a promise.
  • Trusting last-write-wins with data people care about. It loses writes quietly, and clock drift makes it worse.
  • Forgetting the user's own view. Eventual consistency is fine for others' likes, and jarring when your own comment disappears after a refresh.

Check yourself

Try to answer before opening each one - recalling beats re-reading.

1. Why is "choose two of C, A and P" misleading?

Show answer

A distributed system can't opt out of network splits. The real choice is what to do during one: stay consistent by refusing some requests, or stay available and risk stale or conflicting answers.

2. N = 5 and W = 3. What's the smallest R that guarantees a read sees the latest acknowledged write?

Show answer

R = 3, because R + W must be more than N: 3 + 3 = 6 > 5. With R = 2, you get 2 + 3 = 5, and a read could land only on the two copies that missed the write.

3. Which parts of a shopping site need strong consistency?

Show answer

Anything where two different answers break a promise: stock at checkout (don't oversell), payments, and one-time coupon codes. Reviews, view counts and recommendations can be eventually consistent.

Key takeaways

  • During a network split, a replicated system either refuses some requests (consistent) or risks stale answers (available).
  • PACELC: even without a split, strong consistency costs latency.
  • Choose the consistency model per feature: strong for money and uniqueness, eventual for counters.
  • Quorums: R + W > N makes every read overlap the latest write; W = N gives up write availability.
  • Last-write-wins quietly loses data. Merge, use CRDTs, or send each item's writes to one leader.

Quick revise

The whole skill on one page, for the night before an interview.

Everything from the lesson and the deep dive on one page. Skim it before a design interview, and open the full lesson for anything that doesn't ring a bell.

CAP and PACELC in one breath

  • Networks split, so P isn't optional. During a split a replicated system either refuses some requests (CP: etcd, ZooKeeper, a single-leader DB) or answers from what it can reach and reconciles later (AP: Cassandra, DynamoDB by default).
  • "CA" just means "not distributed" - one database server.
  • PACELC: if Partitioned, choose Availability or Consistency; Else, choose Latency or Consistency - strong consistency costs latency on every request.

Pick the model per feature

ModelPromiseGood for
Linearizable (strong)Every read sees the latest writeUnique usernames, seats, balances, locks
CausalCause before effect, for everyoneComments and replies
Read-your-writes / monotonicYou see your own changes; no going back in timeYour profile, your posts
EventualCopies agree once writes stopLikes, views, recommendations
SituationReach for
Money, inventory, uniqueness, locksSingle leader with sync replication, or a consensus store
User must see their own changeRead their requests from the leader for a short while
Counters, likes, analyticsEventual, ideally CRDT counters
Writes from many regionsAP store with conflict resolution, or a home region per item

Quorums (N copies, W to write, R to read)

R + W > N → every read overlaps the latest acknowledged write. N = 3: 2/2 balanced; 3/1 fast reads but any down copy stops writes; 1/1 fastest and possibly stale. N = 5, W = 3 → R = 3.

When copies disagree

Last-write-wins (simple, silently loses data, clock skew picks the wrong winner) · keep both and merge (vector clocks) · CRDTs that merge themselves · avoid conflicts with one leader per item.

The traps

  • "We'll pick CA."
  • Strong consistency everywhere - latency on every request, unavailability during failures.
  • Last-write-wins for data people care about.
  • Eventual consistency for the user's own edit - their comment vanishes on refresh.
  • Assuming quorums are linearizable.

Staff-level points, one line each

  • Linearizable = single objects, real time (the C in CAP). Serializable = transactions in some serial order. Strict serializable = both (Spanner, FoundationDB).
  • Raft: a leader per term appends, commits on a majority, and only an up-to-date node can win an election - no committed write lost. 2f + 1 nodes survive f failures; 4 nodes survive only 1.
  • Linearizable reads need leadership confirmed (ReadIndex) or a time lease - a cut-off leader may not know it was replaced.
  • Cross-region commit waits for the closest majority: Virginia + Oregon (65 ms) + Dublin (75 ms) → ≥ 65 ms; with five regions → ≥ 75 ms. Keep voters in one region, or use home regions and follower reads.
  • Quorum fine print: racing writes have no agreed order; sloppy quorums + hinted handoff break the overlap during failures; read repair and Merkle-tree anti-entropy converge copies.
  • Write availability at 1% downtime per copy: N=3 W=2 99.97%, N=3 W=3 97.03%, N=5 W=3 99.999%. W = N turns every failure into a write outage.
  • Ordering without trusted clocks: Lamport / vector clocks, hybrid logical clocks (CockroachDB), TrueTime commit wait (Spanner).
  • CRDTs (G-counter, PN-counter, OR-set) merge in any order but can't enforce cross-replica invariants like "balance ≥ 0"; tombstones need cleanup.
  • Split brain → fencing tokens that storage checks. GitHub's 2018 incident: a 43-second partition led to ~24 hours of degraded service. Jepsen shows defaults losing acknowledged writes - test what you rely on.

Say it in an interview

  • "Seat reservations need linearizability, so they go through a consensus-backed store; the like counter is eventually consistent."
  • "During a partition, the side without the leader rejects writes - we choose consistency for checkout."
  • "N = 3 with W = 2 and R = 2, so reads overlap writes and either survives one replica down."
  • "I wouldn't use last-write-wins for documents; offline edits merge with CRDTs."

Practice

This skill comes with 11 multiple-choice questions that tell you which misconception a wrong answer reveals. Your answers are graded and your mastery is tracked, so you'll know when the skill holds up. Running code and saving progress need a free account.

Practice CAP, Consistency Models and Quorums free

Practice CAP, Consistency Models and Quorums free

No card needed. Lessons, practice questions and easy problems are free forever.

Free plan, no card · 7-day Pro trial · Cancel anytime