All posts
System Design Mastermind · F08
  • System design
  • Interview prep
  • Consistency
  • CAP theorem

Consistency, CAP and quorums: what replicas promise

Foundations F08. What to say when the interviewer asks "CP or AP?": linearizable vs eventual, read-your-writes and causal consistency, CAP stated precisely (and what's a simplification), PACELC and the latency cost of strong reads, quorums with N, W and R, where quorums leak (sloppy quorums, hinted handoff, repair), concurrent writes (last-writer-wins, versions, CRDTs) and choosing consistency per piece of data. Each idea is told as a story you'll remember, with a lab that shows overlap, latency and what happens when copies are cut off.

23 Oct 2026 · 25 min read · interactive

Share

Start here

The moment data lives on more than one machine, every read has a hidden question: which copy answered, and how fresh is it? "Consistency" is the promise a system makes about that answer. Interviewers probe it in almost every design, usually with "is this CP or AP?", and the Senior answer is precise: say what the promise is, what it costs in latency and availability, and which pieces of data need which promise.

This page covers eight ideas: what "consistent" really means (linearizable to eventual), the useful middle (read-your-writes, monotonic reads, causal), CAP stated precisely, PACELC (the latency cost you pay even when nothing is broken), quorums (N, W and R), where quorums leak (sloppy quorums, hinted handoff, repair), concurrent writes (last-writer-wins, versions, CRDTs), and choosing consistency per piece of data. Replication and leader failover were on the previous pages; consensus (Raft, Paxos), clocks and leases come on the next one.

The one story for this page

Monsoon week at a bank with three branches

Picture a small cooperative bank with three branches, in Mumbai, Pune and Nashik. Each branch keeps its own copy of every account's ledger, and the branches phone each other to keep the copies in step. In monsoon week the phone lines are unreliable. One week touches every idea on this page:

  • Asha deposits ₹5,000 in Pune and checks her balance in Nashik ten minutes later. Should she see it? (strong vs eventual)
  • At the very least she must see her own deposit, and the notice "loan approved" must never appear before "loan applied". (read-your-writes, causal)
  • The line to Nashik goes down. Does Nashik keep paying out withdrawals, or close the counter? (CAP)
  • Even on a sunny day, phoning Mumbai before every passbook entry makes the queue slow. (PACELC)
  • The rule: a withdrawal is valid once two of the three branches have stamped it; a balance check asks two branches. (quorums)
  • With Nashik unreachable, Pune writes Nashik's entry in its own register with a note "give to Nashik". (sloppy quorum, hinted handoff)
  • Both Pune and Mumbai change the nominee on a joint account the same afternoon. Which one stands? (concurrent writes)
  • The manager decides: balances strict, the interest-rate notice board can be a day late. (consistency per piece of data)

The bank is made up for teaching; it is not any real bank's system.

✅ Seen: a company said so (cited)🔶 Inferred / typical🧭 Interview choice

What "consistent" means: from linearizable to eventual

Linearizable (strong) means the system behaves as if there were one copy: once a write finishes, every later read anywhere sees it; eventual means copies agree only after writes stop, with no promise about what you read meanwhile.

The story · remember it like this

The station board and the morning paper

At a railway station there is one departure board. When the 7:15 to Pune is moved to platform 3, the board changes, and from that moment everyone who looks, from any corner of the station, sees platform 3. Nobody can see 3 and then, a minute later, see the old platform 5 again. That's linearizable: one truth, and once it changes, nobody goes back in time.

Now think of the morning newspaper. The Mumbai edition prints the new train timings today; the Nashik edition gets them tomorrow; a stall still selling yesterday's paper shows the old ones. If the railway stops changing timings, every edition will agree in a day or two. That's eventual consistency: all copies agree in the end, but what you read today depends on which copy you picked up.

What it really is
  • Linearizability (Herlihy and Wing, 1990; what people usually mean by "strong consistency"): every operation appears to take effect at one instant between its start and its end, in an order that matches real time. If my write finished before your read started, you see my write or something newer. It is a promise about single items.
  • Eventual consistency: if no new writes arrive, all copies eventually return the same value. Nothing about how long "eventually" is, or what you read in the meantime: an old value, or the new one and then the old one again.
  • Between them sit useful middle grounds (next section).

Three different "C"s, often confused:

  • C in ACID: the database keeps your rules (a balance never goes negative). Nothing to do with copies.
  • C in CAP: linearizability, as above.
  • Isolation (serializable, snapshot): how concurrent transactions over many rows interact; covered on the databases page. "Strict serializability" (Spanner calls it external consistency) is serializable transactions plus real-time order.
In a real system ✅ Seen · AWS, Dec 2020

Amazon S3 switched to "strong read-after-write consistency automatically for all applications" in December 2020, including list operations, "without changes to performance or availability" and "at no additional cost". AWS noted that customers could remove the extra infrastructure they had built to cope with the old behaviour (AWS, Dec 2020).

DynamoDB lets each read choose. An eventually consistent read (the default) "might not reflect the results of a recently completed write"; a strongly consistent read returns "the most up-to-date data". The strong read costs twice as much: one read unit per 4 KB instead of half a unit. Reads from global secondary indexes and streams are always eventually consistent (AWS docs, checked Oct 2026).

Trade-offs
  • Linearizable: simple to reason about, but every read or write must coordinate with other copies, which costs latency and fails when they can't be reached.
  • Eventual: fast, cheap and always answers from the nearest copy, but the application must cope with old and out-of-order answers.
Say it in the interview

When I say strong here I mean linearizable for this item: once the seat is booked, no read anywhere shows it free. For the seat map shown while browsing I'm fine with eventual; a few seconds old is OK.

Trap

Saying "the database is consistent because it's ACID". ACID's C is about your rules inside one database, not about whether a replica in another zone returns the latest value.

The useful middle: read-your-writes, monotonic reads and causal

Most apps don't need everyone to see everything at once; they need each user to see their own changes, never to go back in time, and never to see a reply before the message it answers.

The story · remember it like this

Congratulations before the news

Your cousin posts "We're engaged!" in the family WhatsApp group. Your aunt replies "Congratulations!!". Now imagine a version of the app where, on your uncle's phone, the aunt's "Congratulations!!" arrives first, and the engagement news ten seconds later. For ten seconds he thinks she's congratulating someone on nothing.

Nobody needed the whole family to see the news at the same instant. What mattered was the order: the reply must never show up before the message it answers. That's causal consistency.

And when your cousin sends the news, it must appear on her own phone straight away; she'd panic if it vanished and came back. That's read-your-writes.

What it really is

Four session guarantees (Terry et al., 1994), each cheap on its own:

  • Read-your-writes: after you write, your own reads see it.
  • Monotonic reads: once you've seen a value, you never see an older one (no going back in time when your requests hit different replicas).
  • Monotonic writes: your writes are applied in the order you made them.
  • Writes-follow-reads: if you write after reading something, everyone who sees your write also sees what you read first.

Causal consistency combines them across users: if B could have been influenced by A (a reply to a message, a comment on a post), everyone sees A before B. Unrelated writes may appear in different orders in different places.

How it's built: the client carries a token (the latest version or timestamp it has seen), and a replica only answers once it has caught up to that token. No global coordination is needed.

Precise point: causal consistency is about the strongest model that can keep answering during a network partition, but only if each client keeps talking to the same replicas ("sticky" availability, per Jepsen's map). Linearizability can't.

In a real system ✅ Seen · Microsoft; MongoDB

Azure Cosmos DB offers five levels: strong, bounded staleness, session, consistent prefix and eventual. Microsoft calls session "the most widely used consistency level": within a client session it guarantees read-your-writes and writes-follow-reads. Strong and bounded-staleness reads use two replicas and cost twice the request units of the weaker levels (Microsoft Learn, checked Oct 2026).

MongoDB's causally consistent sessions give all four guarantees, including through a failover, only with "majority" read concern and "majority" write concern; weaker combinations can lose them when two nodes briefly both think they are primary (MongoDB docs, checked Oct 2026).

Trade-offs
  • Session guarantees are cheap and cover most user-visible complaints ("my post disappeared"), but say nothing about what other users see.
  • Causal needs dependency tracking (tokens, version vectors) and still allows two unrelated writes to appear in different orders in different places.
Say it in the interview

Feeds and comments don't need linearizability. I'll give each user read-your-writes with a session token, and keep replies causally after the post they answer. That's achievable from the nearest replica without a cross-region round trip.

Trap

Jumping from "eventual is too weak" straight to "make it strongly consistent". Usually the complaint is one user's own view, which a session guarantee fixes at a fraction of the cost.

CAP, stated precisely

When the network splits your copies, each request on the cut-off side must either wait or fail (stay consistent) or answer with what it has (stay available); you can't have both during the split, and when there's no split, CAP says nothing.

The story · remember it like this

Two ticket counters and a cut phone line

A single-screen cinema in a small town has two ticket counters, one at each gate. There's one seat chart, so the two clerks phone each other before selling any seat: "I'm selling F7." Then the phone line goes dead an hour before the Friday first-day-first-show.

Each clerk now has exactly two choices. Stop selling until the line comes back: no seat is ever sold twice, but the queue gets angry and nobody gets a ticket at that gate. Or keep selling from their own copy of the chart: everyone gets served, and some evening two people will turn up with tickets for F7.

There is no third option. A clever clerk can't both sell freely and guarantee no double booking while they can't talk. That's CAP.

What it really is

Brewer's conjecture (2000), proved by Gilbert and Lynch (2002), with its terms defined narrowly:

  • C = linearizability (not ACID's C).
  • A = every request received by a non-failed node gets a non-error response. Total availability, much stricter than a 99.99% SLA.
  • P = the network may lose or delay messages between nodes (a partition).

The result: if a partition happens, a system can't provide both C and A. Since you can't promise the network never splits, the real choice is what each operation does during a split:

  • CP behaviour: requests on the minority side wait or fail. Nothing stale or conflicting is served.
  • AP behaviour: every side keeps answering from local copies; reads may be stale and writes may conflict, to be merged later.

What's a simplification:

  • "Pick two of three" is misleading: "CA" isn't an option for a system spread over a network; it just means you haven't decided what happens in a partition.
  • Most real databases are neither strictly CP nor AP (a single leader with async followers is neither), and many let you choose per request.
  • CAP only covers partitions. It says nothing about the far more common cost: latency on a normal day (next section).
In a real system ✅ Seen · Brewer, Feb 2017

Eric Brewer, writing about Google's Spanner in 2017: technically Spanner is CP (during a partition it "chooses C and forfeits A"), but its availability is "more than five 9s", so "its users can and do assume CA". The network "contributed less than 10% of Spanner's already rare outages". The point: CP doesn't mean often down, if partitions are rare and the majority side keeps serving (Google Cloud blog, Feb 2017).

Martin Kleppmann (2015) found that common databases fit neither label precisely under CAP's definitions, and argued for retiring "CP" and "AP" in favour of saying exactly what each operation guarantees.

Trade-offs
  • CP: no stale reads or double bookings, but the minority side returns errors during a split. Right for seats, stock, money and unique usernames.
  • AP: always answers, but reads can be stale and writes can conflict. Right for carts, likes, feeds, presence and metrics.
Say it in the interview

Partitions will happen, so the question is what each operation does during one. For seat booking I'd rather return an error on the minority side than sell a seat twice. For browsing and likes I'd keep serving from local copies and reconcile later.

Trap

Saying "we pick CA" or "MongoDB is CP, Cassandra is AP" as if that settles it. The interviewer will ask what happens to a write on the minority side, and the answer depends on settings, not the brand.

PACELC: the price you pay on a normal day

If there's a Partition, choose Availability or Consistency; Else, even when everything works, choose lower Latency or stronger Consistency, because waiting for other copies takes time.

The story · remember it like this

Phoning home before every purchase

Two sisters share one bank account and go shopping at Sarojini Nagar market on the same afternoon, in different lanes. To be sure they never overspend, they agree: before buying anything, phone the other one and confirm the balance.

The network is fine; both phones work. And still every purchase takes an extra two minutes, while the shopkeeper taps his foot. Nothing is broken; this is simply the price of checking.

So most days they agree on something looser: buy small things freely, and phone only before anything over ₹2,000. Faster for most purchases; and once in a while they both buy the same kurta.

What it really is

PACELC (Daniel Abadi, 2012) adds the part CAP leaves out:

  • PA / PC: during a partition, favour availability or consistency (that's CAP).
  • EL / EC: else, in normal operation, favour latency or consistency.

Why EL/EC matters more day to day: partitions are rare, but every single request pays for coordination. A strongly consistent read or write must hear from other copies, and you wait for the slowest one you need.

  • Same zone: well under a millisecond; across zones in a region: around a millisecond or two; across regions: tens to hundreds of milliseconds (rounded, typical).

Abadi's examples: Dynamo, Cassandra and Riak are PA/EL by default (and let you raise quorums to trade latency for consistency); VoltDB/H-Store and Megastore are PC/EC; Yahoo's PNUTS is PC/EL.

In a real system ✅ Seen · Abadi 2012; PBS 2012

Bailis et al. measured this trade on production latency data (VLDB 2012). With LinkedIn's SSD-backed data, reading and writing one copy each (R=W=1) cut latency by 59.5% compared with a strict quorum, and reads were consistent within 1.85 ms of a write with 99.9% probability. With Yammer's Riak data, R=2, W=1 cut the 99.9th-percentile latency by 81% (186.7 ms) compared with the fastest strict quorum, with a 202 ms window for stale reads.

DynamoDB global tables' multi-Region strong consistency mode replicates each change "synchronously to another Region before the write returns": a cross-region round trip on every write, in exchange for strong reads in any Region (AWS docs, checked Oct 2026).

Trade-offs
  • EL: the nearest copy answers, so requests are fast and steady; you accept a short window of stale reads.
  • EC: every request waits for other copies, so the slowest needed copy sets your latency, and a cross-region quorum puts a long round trip on every request.
Say it in the interview

Even without failures, strong reads cost me a round trip to a quorum. Inside one region that's a millisecond, so I'll pay it for inventory. Across regions it's 50 to 100 milliseconds, so I'll keep each item's quorum in its home region and replicate elsewhere asynchronously.

Trap

Treating CAP as the only trade-off and forgetting latency. The interviewer's next question is often "what does strong consistency cost when nothing is broken?"

Quorums: N copies, write to W, read from R

Keep N copies, let a write succeed once W have it and a read ask R and keep the newest; if W + R > N the two groups always share a copy, so a read can't miss the latest acknowledged write.

The story · remember it like this

The housing-society committee

A housing society has five committee members, and each keeps a copy of the parking allotment register. The rule for changing a slot: get the change signed into the registers of at least three members. The rule for checking who owns a slot: ask any three members and believe the newest entry.

Why does this work? Any group of three and any other group of three, out of five people, must share at least one person. So whenever you ask three members, at least one of them signed the latest change.

And the society keeps working if two members are travelling: three are still around to sign and three to ask. If three are away, nothing can be changed until someone comes back.

What it really is
  • N: copies of each item (usually 3; 5 for more failure tolerance).
  • W: copies that must confirm a write before it's acknowledged.
  • R: copies a read asks; it returns the newest version among the answers.
  • W + R > N: every read group overlaps every write group, so at least one copy in any read has the latest acknowledged write.
  • Failure tolerance: writes keep working with N − W copies down, reads with N − R down. A majority (W = R = ⌊N/2⌋ + 1) balances the two: with N = 3, either survives one copy down; with N = 5, two.
  • Latency: requests go to all copies in parallel and you wait for the W-th (or R-th) fastest, so a slow copy only hurts if you need it.
  • Tuning: W = N, R = 1 gives fast reads and fragile writes; W = 1, R = N the opposite; W = R = 1 is fast and available but gives no overlap.
In a real system ✅ Seen · Dynamo; Aurora

The Dynamo paper (SOSP 2007): "The common (N,R,W) configuration used by several instances of Dynamo is (3,2,2)", and a typical service required "99.9% of the read and write requests" to finish within 300 ms.

Amazon Aurora keeps six copies across three Availability Zones, with a write quorum of 4 and a read quorum of 3. It can lose a whole zone (two copies) and keep writing, and lose a zone plus one more copy without losing data, since three copies are still a read quorum (AWS Database Blog, Aug 2017).

Cassandra lets each query pick a level (ONE, QUORUM, ALL, LOCAL_QUORUM and others) and notes that choosing levels whose replica sets overlap, such as QUORUM for both, makes "all acknowledged writes ... visible to subsequent reads" (Apache Cassandra docs, checked Oct 2026).

Trade-offs
  • Majority quorums: survive a minority of failures with no failover step and hide slow copies, but every read and write does work on several copies.
  • Partial quorums (W + R ≤ N): faster and more available, but a read right after a write can miss it; usually only for milliseconds, with no promise.
Say it in the interview

Three copies, one per zone, writes and reads at QUORUM: two of three. W + R = 4 > 3, so reads see the latest acknowledged write, and we survive losing a zone for both reads and writes. Latency is the second-fastest zone, about a millisecond.

Trap

Quoting W + R > N as if it made the system linearizable. It guarantees overlap with the latest acknowledged write; the next section is everything it doesn't cover.

Try it: Quorums: overlap, latency and a cut network

Choose how many copies to keep, how many a write waits for and how many a read asks, then cut copies off. Each row shows the arithmetic: whether reads can miss the latest write, what waiting costs on a normal day, and what happens on each side of a cut.

Start from

A shopping cart that must never refuse an "add to cart": three copies across zones, and each write and read waits for just one of them (N=3, W=1, R=1).

Copies live in
Too few copies answer
CopyWhereRound tripState
#1Zone A500 µsreachable
#2Zone B1.0 msreachable
#3Zone C2.0 msreachable
What we're sizingNumberHow we got itSo we decide
1 · Does every read meet the latest write?
Stale read right after a writeThe read and write groups must share at least one copy, like two committees that always have a member in common. When they can't, a read may ask only copies that haven't heard the news yet. Background copying closes that gap, usually within milliseconds in one region, but nothing promises it.67%
W + R = 1 + 1 = 2 ≤ N = 3
chance a read of 1 copy misses every fresh copy (1 of 3 have the write) = C(3−1, 1) ÷ C(3, 1) = 2 ÷ 3 = 67%
a majority of 3 is 2; W = R = 2 is the usual "QUORUM" setting
Fine for data where an old answer is harmless for a moment: carts, likes, view counts, profiles. Raise W or R for anything else.
2 · What waiting for more copies costs (even with no failure)
Write · readThis is the "else" in PACELC: even on a perfect day, a stronger answer means waiting for copies further away. In one region that's a millisecond or two; across regions it's a long round trip on every request.500 µs · 500 µs
requests go to all copies at once; a write returns when the 1st fastest reachable copy answers → 500 µs
a read returns when the 1st fastest answers → 500 µs; the nearest copy alone takes 500 µs
each read does 1× the replica work of a single-copy read
In one region the extra wait is small, so majority quorums are a cheap default for important data.
3 · When copies are cut off
Reachable copiesHere is CAP in one card. When too few copies can be reached, a system can refuse (stay consistent, lose availability on this side) or carry on with whatever it can reach (stay available, lose consistency). It can't do both.3 of 3
writes need 1 → keep working with up to N − W = 2 cut off
reads need 1 → keep working with up to N − R = 2 cut off
right now 0 are cut off → writes succeed, reads succeed
Nothing is cut off. Try 'Copies cut off' to see which choice this setup makes.
4 · Verdict for this setup
What you getFast and always up, but reads can be stale1 + 1 ≤ 3, so a read can land entirely on copies that haven't received the write yet: right after a write, that happens 67% of the time. Background copying usually closes the gap within milliseconds in one region, so most reads are fine; but nothing promises it. Writes survive 2 copies being unreachable, reads 2. Good for a cart or a view count; raise W or R where a stale read would hurt.

Try: on Cart, set R to 3 and stale reads drop to zero while writes stay fast. On Majority, cut off 2 copies and both reads and writes stop. On 6 copies, cut off a third copy: reads still work, writes don't. On Regions cut off, switch to stand-ins and the Mumbai side keeps working while Hyderabad and Singapore fall behind. Copies are spread evenly and cut off from the farthest place first. Round-trip times are rounded, typical teaching values, not any provider's figures; the stale-read chance is the moment right after a write, before background copying (Bailis et al., 2012).

Where quorums leak: sloppy quorums, hints and repair

Real quorum systems bend the rule to stay available (writing to stand-in nodes), repair copies in the background, and pick "newest" by timestamp, so W + R > N is a strong hint, not a proof of linearizability.

The story · remember it like this

The parcel left with the neighbour

A courier comes to deliver your parcel, but you're out. Instead of taking it back, he leaves it with the neighbour across the corridor, with a note: "for flat 402". The delivery counts as done; the courier's app shows "delivered".

You come home and check your doorstep: nothing. As far as you can tell, the parcel never arrived. It's only when the neighbour comes back from the market and hands it over that your flat has it.

That's a sloppy quorum with hinted handoff: the write was acknowledged, but not by the copies a reader would check.

What it really is

How real systems stray from the textbook quorum:

  • Sloppy quorum: when some of an item's own replicas are unreachable, the write goes to other healthy nodes so it can still succeed. Dynamo used "the first N healthy nodes from the preference list". Great for availability (an AP move), but the W copies may not overlap the R copies a reader asks.
  • Hinted handoff: the stand-in keeps the data with a hint naming the real owner, and hands it over when the owner returns.
  • Read repair and anti-entropy: when a read finds copies disagreeing, it fixes the stale ones; a background process compares copies (often with Merkle trees) to catch the rest.
  • Failed writes leave traces: a write that reached fewer than W copies is reported as failed, but isn't rolled back on the copies that took it, so a later read may still return it.
  • Concurrent reads and writes: while a write is spreading, one read can see the new value and the next the old one, unless reads also write back what they found before returning.
  • "Newest" by timestamp: if clocks are skewed, the later write can lose.

Precise point: linearizability needs more than overlapping counts. It needs one agreed order of writes, which is what consensus (Raft, Paxos) provides. That's the next Foundations page.

In a real system ✅ Seen · Dynamo; Cassandra

The Dynamo paper describes sloppy quorums and hinted handoff exactly this way: "all read and write operations are performed on the first N healthy nodes from the preference list", and nodes receiving hinted replicas "keep them in a separate local database" until they can be delivered (SOSP 2007).

Cassandra's ANY level accepts a write once "one replica or a stored hint" has it, and it resolves conflicts by timestamp, so it recommends keeping clocks synchronised with NTP (Apache Cassandra docs, checked Oct 2026).

Trade-offs
  • Sloppy quorums and hints keep writes flowing through node failures, at the cost of reads that can miss them until the hint is delivered.
  • Read repair and anti-entropy make copies converge without a leader, but add read cost and background I/O.
Say it in the interview

With quorum reads and writes I get read-after-write for acknowledged writes, but not linearizability: sloppy quorums, failed partial writes and timestamp ordering can all surprise me. Where I need a single order, like seat booking, I use a single leader per item or a consensus-backed store.

Trap

Claiming "Cassandra with QUORUM is strongly consistent" without caveats. A good interviewer will ask about hinted handoff, a write that failed on one replica, or two clients writing the same key in the same millisecond.

Concurrent writes: last-writer-wins, versions and CRDTs

When two copies accept different writes to the same item, something must decide the result: keep the latest timestamp (simple, silently drops one), keep both and let the app merge (versions), or use data types that merge by themselves (CRDTs).

The story · remember it like this

The wedding guest list in two notebooks

A wedding is being planned in two cities. In Hyderabad, the bride's mother adds ten names to her notebook. In Vijayawada, the bride's father adds eight to his. On Sunday they compare. Merging is easy: the final list is everyone in either notebook. Nobody's work is lost, and it doesn't matter who compared first.

Then they look at one line: "caterer". The mother wrote "Ramu's", the father wrote "Sri Lakshmi". If the rule is "whoever wrote last wins", someone's choice silently disappears, and they may not even notice. A better rule is to notice the clash and ask them both.

And a trap: the mother crossed out Uncle Suresh, but he's still in the father's notebook. Union brings him back.

What it really is

Three ways to resolve concurrent writes:

  • Last-writer-wins (LWW): each write carries a timestamp; the highest wins. Simple and always converges, but one of two concurrent writes is silently lost, and clock skew can make an older write win.
  • Version vectors (vector clocks): each copy tracks which writes it has seen. The system can tell "B came after A" (keep B) from "A and B were concurrent" (keep both as siblings and let the application merge).
  • CRDTs (conflict-free replicated data types; Shapiro et al., 2011): counters, sets, maps and text designed so that merging in any order gives the same result. Copies converge with no coordination ("strong eventual consistency"). Deletes need care: a removed item can come back unless the type records removals.

The design choice: avoid conflicts where you can (one leader per item, route each user to a home region), and where you can't, pick the merge rule deliberately for each field.

In a real system ✅ Seen · Dynamo; Figma

Dynamo's shopping cart: "an 'Add to Cart' operation can never be forgotten or rejected", so concurrent versions are kept and merged; the paper notes that deleted items can resurface. In practice conflicts were rare: over 24 hours, "99.94% of requests saw exactly one version" (SOSP 2007).

Figma's multiplayer editing is "inspired by" CRDTs but, since its server is the central authority, it keeps the last value the server received for each property of each object: a last-writer-wins register ordered by the server, not by clocks (Figma, 2019).

Cassandra resolves every conflict by last write wins on timestamps (Apache Cassandra docs, checked Oct 2026).

Trade-offs
  • LWW: no extra work, fine when overwriting is the intent (a profile photo, a status), wrong when both writes matter (stock counts, list items).
  • Versions and CRDTs: no silent loss, but more metadata, merge logic in the app, and data types that don't fit every rule (a CRDT can't stop two people booking the last seat).
Say it in the interview

For the profile, last-writer-wins is fine; the latest photo is what the user wants. For the cart I'd merge as a set so no add is lost. For stock I won't merge at all: one leader per item, so conflicts can't happen.

Trap

Choosing multi-region writes and saying conflicts are "resolved by timestamp" without admitting that one write is silently thrown away, or that clocks drift.

Choosing consistency per piece of data

Consistency isn't a setting for the whole system; for each kind of data ask "what goes wrong if a read is a few seconds old, or two writes clash?", and pay for strong guarantees only where the answer is real harm.

The story · remember it like this

The hospital ward

In a hospital, a patient's allergy list must be exactly current. If a nurse in the night shift sees yesterday's version and gives penicillin, the cost is a life. So the ward insists on one record, and checks it every time, even though that's slower.

The canteen menu on the ward's notice board can be an hour out of date. Nobody is harmed if Tuesday's menu says dosa and they're serving idli.

The visitor count shown at reception can be a few minutes behind, and it doesn't matter if two receptionists' counts disagree for a while.

Same building, same staff, three different promises, chosen by what goes wrong when the data is old.

What it really is

A quick sorting rule for interviews:

  • Strong (linearizable, single leader or consensus): anything with an invariant you can't repair later. Money and balances, stock and seats, unique usernames, locks, "is this coupon already used".
  • Read-your-writes / causal (session tokens): what users create and immediately look at. Their own posts, settings, cart, a chat thread's order.
  • Eventual (nearest copy, async replication, caches): what's read a lot and harmless when slightly old. Like and view counts, feeds, recommendations, product pages, search indexes, analytics.

Then say how you get each one:

  • Strong: route reads to the leader, or use quorum or consensus reads; accept the latency and the minority side failing in a partition.
  • Session: a version token with every request; read from a replica only once it has caught up.
  • Eventual: read any replica or cache; bound the staleness with a TTL or replication-lag alerts.

Most products let you choose per request: DynamoDB's ConsistentRead flag, Cassandra's level per query, Cosmos DB's per-request level, MongoDB's read and write concerns.

In a real system 🧭 Interview choice · by data

A ticketing design (a common interview question) splits it exactly this way: browsing events and the seat map can be eventually consistent and served from replicas and caches, while reserving a seat must be strongly consistent so a seat is never sold twice. Third-party prep guides frame CAP the same way, as a choice per feature, not per system (Hello Interview, third party, checked Oct 2026).

DynamoDB makes the cost of the choice visible: the same 4 KB read costs half a read unit eventually consistent and one unit strongly consistent, so you pay for strong reads only where you ask for them (AWS docs, checked Oct 2026).

Trade-offs
  • Per-data choices give you speed where it's safe and safety where it matters, at the cost of more decisions to explain and test.
  • One strong setting everywhere is simpler, but slower and less available than it needs to be; one weak setting everywhere is fast until it sells the same seat twice.
Say it in the interview

Seat reservation is strongly consistent: one leader per event, conditional write on the seat. Everything around it, event pages, search, the seat map preview, is eventually consistent from replicas and cache, and the user sees their own booking straight away through read-your-writes.

Trap

Choosing one consistency level for the whole design. "The system is eventually consistent" invites "so two people can buy the last ticket?"

Remember it

One line per idea. Read this the night before.

  1. Linearizable = behaves like one copy; once a write finishes, every read sees it. Eventual = copies agree only after writes stop. ACID's C is something else.
  2. Most apps need read-your-writes, monotonic reads and causal order, not linearizability; a session token gets them from the nearest replica.
  3. CAP: during a partition each operation either fails on the minority side (C) or answers from what it has (A). No partition, no CAP choice. "CA" isn't an option.
  4. PACELC: else, latency vs consistency. Strong reads wait for other copies on every request; across regions that's a long round trip.
  5. Quorums: W + R > N means reads overlap the latest acknowledged write. Writes survive N − W failures, reads N − R. Majority 2 of 3 is the default.
  6. Quorums leak: sloppy quorums and hints, failed partial writes, read repair and timestamp ordering. Overlap is not linearizability; consensus is.
  7. Concurrent writes: LWW drops one silently; versions keep both for the app; CRDTs merge by themselves. Best of all: one leader per item, so they can't clash.
  8. Per piece of data: strong for money, stock, seats and uniqueness; session for a user's own data; eventual for counts, feeds and pages.

Check yourself

Answer out loud, then open.

An interviewer asks: "Is your design CP or AP?" How do you answer well?

Answer per operation, and only about partitions.

  • Name the operation: "Seat reservation is CP: during a partition, the side without the seat's leader returns an error rather than risk a double booking."
  • Name the rest: "Browsing, search and likes are AP: they keep serving from local replicas and caches, and may be a few seconds stale."
  • Add the normal-day cost: "Even without a partition, the reservation pays a round trip to the leader; the browse path reads the nearest copy."

Say it CAP is a per-operation choice about partitions; on a normal day the trade is latency versus consistency.

N = 3, W = 1, R = 1. A user updates their profile and immediately reloads it. What can happen, and what are two fixes?

The reload can return the old profile. Right after the write only one copy has it, and a read of one copy picks one of the other two two times in three (C(2,1) ÷ C(3,1) = 2/3), until background copying catches up, usually within milliseconds.

Fixes:

  • Read-your-writes with a session token: the client sends the version it wrote, and a replica answers only once it has that version (or the request goes to the copy that took the write).
  • Raise the quorum for this data: W = 2, R = 2 gives W + R = 4 > 3, at the cost of waiting for a second copy.
Why isn't W + R > N enough for linearizability?

Overlap only guarantees that a read's answers include a copy that took the latest acknowledged write. Several things break the stronger promise:

  • Sloppy quorums: stand-in nodes took the write, so the overlap isn't with the copies the reader asks.
  • A write that failed (fewer than W copies) isn't rolled back, so it can appear later.
  • While a write is spreading, one read can see the new value and a later read the old one, unless reads write back before returning.
  • "Newest" is decided by timestamps, and clocks drift.

Linearizability needs one agreed order of operations: consensus (Raft, Paxos) or a single leader per item.

Three copies, one per region (Mumbai, Hyderabad, Singapore), with majority quorums. A fibre cut isolates Mumbai. What happens to users in Mumbai, and what are your options?

Mumbai can reach only one copy, so it can't form a majority of two: with strict quorums, writes and reads from Mumbai fail. Hyderabad and Singapore can still reach each other and keep working.

Options:

  • Accept it for data that must be correct (bookings, money): route Mumbai users to the majority side if their requests can get there, or show a clear error.
  • For data that can tolerate staleness (carts, likes), allow sloppy quorums or local writes in Mumbai and merge after the cut heals.
  • Rethink placement: keep each item's quorum inside its home region (three zones, LOCAL_QUORUM) and replicate across regions asynchronously, so a regional cut affects only cross-region freshness.
Two users edit the same field in two regions at the same moment. Compare last-writer-wins, versions and CRDTs.
  • Last-writer-wins: keep the higher timestamp. Simple and always converges, but one edit is silently lost, and clock skew can make the older edit win. Fine for "set my status".
  • Versions (version vectors): detect that the edits were concurrent and keep both as siblings for the app or user to merge. No silent loss, more work.
  • CRDTs: if the field is a counter, set or text designed to merge, both edits survive automatically in any order. Not possible for every rule: no CRDT stops two people taking the last seat.

Say it For fields with an invariant I avoid the conflict entirely with one leader per item; for the rest I choose the merge rule per field.

Strong consistency costs latency even with no failures. Show it with numbers.

Take three copies in three zones, about 0.5, 1 and 2 ms away (rounded, typical).

  • W = 1: a write returns after the nearest copy, about 0.5 ms.
  • W = 2: it waits for the second fastest, about 1 ms.
  • Now put the copies in Mumbai, Hyderabad and Singapore, about 1, 25 and 60 ms away from a Mumbai coordinator. W = 2 means about 25 ms on every write; strong reads the same.

That's PACELC's "else": the system works perfectly and still pays for consistency on every request. It's why cross-region designs keep each item's quorum in one region.

Which of these need strong consistency: a like count, a unique username, a user's own settings page, a bank transfer, a product's review list?
  • Unique username: strong. Two people must not get the same name; use a conditional write on one leader or a consensus-backed store.
  • Bank transfer: strong, inside a transaction, plus idempotency so retries don't double-pay.
  • User's own settings: read-your-writes is enough; other people can see the change a moment later.
  • Like count and review list: eventual. A few seconds old is harmless; counts can even be approximate.

Say it I pay for strong consistency only where an old or clashing value causes harm I can't undo.

Where you'll use this in the series

Sources

Checked October 2026. Definitions come from the papers listed (Herlihy & Wing via Jepsen, Terry et al. 1994, Gilbert & Lynch 2002, Dynamo 2007, Shapiro et al. 2011, Abadi 2012, Bailis et al. 2012) and the official AWS, Microsoft, MongoDB and Apache Cassandra docs; company statements are as published on the dates shown (Kleppmann 2015, Brewer 2017, AWS 2017 and 2020, Figma 2019) and may have changed since. The lab's round-trip times are rounded, typical teaching values; its stale-read chance is Bailis et al.'s formula for the moment right after a write.

System Design Mastermind · Foundations

Series home

All of Foundations

18 publishedStart here: the concepts every design uses, each told as a story you'll remember.

F01

How a request travels: DNS, load balancers, gateways and open connections

Name → address (DNS) → open a secure line once and reuse it (TCP, TLS) → nearby copies for static files (CDN) → spread and guard the work (load balancer, gateway) → find colleagues inside (discovery) → keep a line open for live updates.

20 min · interactive Preview
F02

The interview framework: requirements, numbers and scope before boxes

Agree what users must do (three core requirements) → put numbers on how well (p99 latency, availability, durability, staleness) → say what's out of scope → sketch the simple end-to-end design → go deep only where a number breaks it.

22 min · interactive Preview
F03

Back-of-envelope estimation: from users to servers in one minute

Users × actions ÷ 86,400 (≈10⁵) = average per second → × peak factor → split reads and writes → storage = count × size × time × copies → bandwidth × 8 bits → in flight = rate × latency → servers = peak ÷ (capacity × 60%) + 2 spares.

20 min · interactive Preview
F04

APIs and real-time communication: REST, gRPC, retries, webhooks and live updates

Nouns + HTTP verbs (user from the token) → REST outside, gRPC inside → cursor pagination → POST with an Idempotency-Key, retries with backoff and jitter → add, don't change → poll for rare updates, SSE for one-way live, WebSockets for both ways → webhooks are at-least-once → thin connection gateways with resume and push fallback.

22 min · interactive Preview
F05

Databases: data models, indexes and transactions

Relational by default (each fact once, keys, constraints) → key-value / document / wide-column / graph only for a named access pattern → B-tree for reads, LSM for heavy writes → composite index with equality columns first, then the sort → one transaction per local change, made durable by the write-ahead log → know your isolation level → win races with a conditional write and a unique constraint.

24 min · interactive Preview
F06

Replication and sharding: copying and splitting your data

Copies scale reads and survive failures (leader + followers); splits scale writes and size (shards). Replicate first; shard only when data size or write rate outgrows one leader → pick the shard key from the main query → hash it into many fixed slots so growth moves ~1/(N+1) → name your hot key and your one cross-shard query.

25 min · interactive Preview
F07

Caching: hit ratios, invalidation and stampedes

Cache what is read far more than it changes → say the expected hit ratio and size the database for the misses → cache-aside with a TTL; on writes, update the database then delete the key → coalesce misses on hot keys and jitter TTLs → plan for the cache failing or restarting empty, because by then the system depends on it.

24 min · interactive Preview
F08

Consistency, CAP and quorums: what replicas promise

Say what each operation needs, not what the system is: strong (linearizable) for money, stock, seats and uniqueness; read-your-writes for a user's own data; eventual for counts, feeds and pages → during a partition, strong operations fail on the minority side, the rest keep serving (CAP) → on a normal day, strong costs a round trip to a quorum (PACELC) → with N copies, W + R > N makes reads overlap the latest write, but it isn't linearizability.

You're reading this Preview
F09

Coordination: clocks, leaders, locks and consensus

Don't order events across machines by wall-clock time; let one leader assign the order → elect that leader by majority vote with increasing terms, so a split network can't elect two → give it a lease so a dead leader is replaced without anyone proving it died → and a fencing token the storage checks, so a paused old leader can't do harm → use consensus (Raft) for the few decisions that must be agreed, not for every request.

25 min · interactive Preview
F10

Queues and event streams

Put a queue between work that can wait and the caller, so a spike becomes lag instead of an outage → use a task queue for jobs and an event log (Kafka) when many consumers need every event, replay or per-key order → key by the entity whose order matters and size partitions for peak consumers → deliver at least once and make consumers idempotent → retry a few times with backoff, then dead-letter → scale on lag → publish through an outbox, never "save, then publish".

25 min · interactive Preview
F11

Idempotency, exactly-once and sagas

Treat a timeout as unknown, never as failed → make writes idempotent by design (set, don't add; client IDs; conditional writes) → for the rest, an idempotency key per intent, stored with the result in the same transaction as the effect → consumers deduplicate by message ID in the same transaction → exactly-once holds only inside one boundary → across services, use a saga of local steps with compensations, not 2PC → compensable steps first, the pivot (capture payment) next, retryable steps last, on a durable orchestrator.

25 min · interactive Preview
F12

Scaling and performance

State latency as a percentile at a stated load → size each tier to the utilisation where its p99 is still flat (pooled, least-request balancing lets you run hotter) → budget fan-out calls against the page deadline, hedge stragglers → scale up first, scale out stateless tiers → name the shared resource (database, lock, connections) that caps the speed-up → find the saturated resource and cut work per request → pre-scale known peaks, autoscale on the signal that saturates → under overload, shed the lowest-priority work fast and budget retries.

24 min · interactive Preview
F13

Reliability and disaster recovery

Turn the target into a downtime budget → cut hard dependencies, because chains multiply → spread copies across zones (cells for blast radius) → timeouts from the deadline, one layer of jittered retries under a budget → circuit breakers with fallbacks and a bulkhead per dependency → fast, non-flapping health checks (readiness checks dependencies, liveness doesn't) → statically stable: spare capacity already running, config cached → PITR plus tested restores, because replicas copy mistakes → the cheapest DR strategy that meets RTO and RPO, drilled.

25 min · interactive Preview
F14

Observability and safe deployments

Metrics to notice, traces to locate, logs to explain (joined by a trace ID) → watch latency percentiles, traffic, errors and saturation → set an SLO per user journey and treat 1 − SLO as an error budget → page on burn rate over two windows, not on CPU → canary every change on a slice with automated analysis against a baseline → keep every version compatible with its neighbours (expand, migrate, contract) so rollback is always possible → ship dark behind flags, and stage config like code → when it breaks: one commander, mitigate first, blameless postmortem.

25 min · interactive Preview
F15

Security essentials for system design

Prove who the caller is (slow salted hashes, MFA, passkeys, rate-limited login) → carry identity in short-lived signed tokens with revocable refresh tokens, or in sessions you look up → delegate with OAuth code flow + PKCE, sign in with OpenID Connect → check this user against this object on every request, least privilege for people and services, audit logs → TLS 1.3 at the edge, mTLS inside, no trust from network location → envelope encryption with a KMS, secrets in a vault, tokenise what you needn't keep → treat all input as data (parameterise, encode, CSRF tokens, no user-chosen fetches) → absorb floods and abuse at the edge.

26 min · interactive Preview
F16

Search, feeds and geo building blocks

Search: analyse text into terms → inverted index of sorted postings → BM25 or hybrid (BM25 + vectors via RRF) retrieval of ~1,000 candidates → learned ranker → shards with replicas, fed from the database by CDC, refreshed every second. Typeahead: precomputed top-k per prefix in memory. Feeds: push IDs into followers' timelines, pull celebrities at read time, hydrate, filter, rank, page with cursors. Geo: index by cell (geohash, S2, H3), search the cell plus neighbours, exact distance on the few candidates.

27 min · interactive Preview
F17

Data pipelines: batch and stream

Pick batch or stream by how fresh each output must be. Get data in with log-based CDC (snapshot, then the WAL) and schemas that evolve safely; land raw events as Parquet in lakehouse tables partitioned by date. Batch jobs map, shuffle and reduce one partition and overwrite it, so retries and backfills are safe. Stream jobs window by event time, fire on watermarks, decide whether late events wait, correct or drop, and checkpoint state with offsets for exactly-once effect, with transactional or idempotent sinks. Reprocess by replaying retained data (Kappa) rather than keeping two codebases (Lambda).

28 min · interactive Preview
F18

AI foundations: inference, RAG and agents

Latency is time to first token (prefill reads the prompt, compute-bound) plus output tokens × time per token (decode, memory-bound), so stream answers and limit by tokens. GPU memory is weights plus a KV cache per request; long prompts, not users, fill it. Continuous batching shares each weight read across many requests, cutting cost per token by 10× or more until time per token hits its target. Route easy requests to small models, cache shared prompt prefixes, quantize carefully. RAG retrieves, reranks and cites a few permission-filtered chunks; agents are tool-calling loops with budgets, idempotent tools and approval for irreversible steps. Evaluate every change on an eval set, and design so a model fooled by prompt injection still can't do damage.

30 min · interactive Preview

More posts