download

R + W > N, yet reads return new data, then old. Why?

System design~20 minReviewed 29 Oct 2026Free · No sign-in

Question

An order's status is kept on five replicas, A to E (N = 5). A write succeeds once three replicas confirm it (W = 3). A read asks three replicas and returns the reply with the highest version (R = 3). Since 3 + 3 > 5, every read should see the latest write.

Order 42 is at version 7, pending. The payment service starts writing version 8, paid. A user opens the order and sees paid. They refresh and see pending. Nobody wrote pending again.

  1. Give an order of events that causes this.
  2. Change the read so that once a read returns paid, no later read returns pending.
"CODE · PYTHON"
def read_status(order_id):
    replies = ask_replicas(order_id, count=3)  # (version, status) pairs
    version, status = max(replies)  # the highest version wins
    return status
Show hints (3)
  1. "COUNT THE COPIES"

    When the write starts, how many replicas hold version 8? Can a group of three miss all of them?

  2. "WHAT OVERLAP COVERS"

    Any two groups of three out of five share a replica. That helps only once version 8 is on three replicas. Is it yet?

  3. "BEFORE YOU REPLY"

    Read 1 found version 8 on one replica. What could it do before replying, so that every later group of three finds version 8?

Show checked explanation

R + W > N only means a read overlaps every finished write. Version 8 is still in flight, on replica A alone. Read 1 asks A, B, C and gets 8. Read 2 asks C, D, E and gets 7. Fix: before a read replies, it writes the newest version back until W replicas hold it.

"SOLUTION · PYTHON"
from itertools import combinations

replicas = {name: (7, "pending") for name in "ABCDE"}
replicas["A"] = (8, "paid")  # the write of version 8 is still in flight


def read(asked, write_back=False):
    newest = max(replicas[name] for name in asked)
    if write_back:  # must finish before the reply
        for name in asked:  # R = W = 3, so three replicas now hold it
            replicas[name] = max(replicas[name], newest)
    return newest[1]


def old_reads():
    return sum(read(group) == "pending" for group in combinations("ABCDE", 3))


print(read("ABC"), read("CDE"), old_reads(), "of 10 groups")
print(read("ABC", write_back=True), read("CDE"), old_reads(), "of 10 groups")
"OUTPUT"
paid pending 4 of 10 groups
paid paid 0 of 10 groups

Code run on CPython 3.12 against every delivery order of the write and every pair of read groups. Checked by an editor other than the author.

Walkthrough

This order of events breaks it:

stepwhat happensreplicas with v8read returns
1Payment service sends v8; only A has it so farAno read yet
2Read 1 asks A, B, C: versions 8, 7, 7Apaid
3Read 2 asks C, D, E: versions 7, 7, 7Apending

Any two groups of three out of five share a replica. So once v8 is on three replicas, every read finds it. A write still in flight can be on fewer. Here 6 of the 10 possible groups include A and return paid. The other 4 return pending.

While the write runs, either answer alone is fine. The bug is going back in time: read 2 started after read 1 ended, yet returned older data. A linearizable store rules this out: once a read returns a value, every later read returns that value or a newer one.

The fix is a write-back. Before read 1 replies, it sends v8 out and waits until three replicas confirm they hold it, here A, B and C. Every group of three overlaps that set, so all 10 groups now return paid.

The cost is one more round trip. You can skip it when all three replies show the same version: that version is already on three replicas.

Common mistakes

  • Raising R to 4. The group B, C, D, E still misses A and returns pending. Only R = 5 avoids it, and then one slow or failed replica stalls every read.
  • Repairing after the reply. Dynamo's read repair fixes stale replicas after the answer is sent. Read 2 can arrive before the fix and still get pending.
  • Letting a replica accept any write. A late v7 message reaching B after the write-back puts B back to 7. The group B, D, E then returns pending again. Keep only the higher version.

Follow-up questions

  • "Does a real database do this?" Yes. By default, Cassandra repairs the stale replicas it asked before it replies to a quorum read. Its docs call the result monotonic quorum reads. With a table's read_repair option set to NONE, a write that missed a quorum can show up once, then vanish.
  • "What changes with two writers?" Both could pick version 8 for different values, and replicas would disagree on what 8 means. So each writer first asks a quorum for the highest version and adds 1. Adding the writer's id to the version breaks ties.
  • "A replica is down, and a spare node takes the write. Does R + W > N still protect reads?" No. The overlap math assumes the same five replicas every time. With a sloppy quorum, as in Dynamo, a stand-in node can confirm the write in place of a regular replica. A read of three regular replicas can then miss it.

What a strong answer covers

Draws an order with the write still in flight. Says the overlap covers only finished writes. Fixes it with a write-back that completes before the reply, and names its cost.

Open in interactive practice deck →

Original OfferVibe question. Topic idea from System Design Interview: An Insider's Guide (Alex Xu, 2020); text, examples and code are our own.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.