CMD Guide
HomeSystem DesignScalable Systems (Advanced Topics)

hard CAP/PACELC for Replication & Reads

Replication is a consistency decision, not just a scaling knob

CAP says that during a network Partition you must give up either Consistency or Availability — you cannot keep both. PACELC completes the sentence for the common case: if Partitioned, choose A or C; Else (normal operation) choose Latency or Consistency. The moment you add a replica, you have taken a PACELC stance whether you meant to or not, because when the write reaches the replica is the whole question.

A client writes name=Alice to the primary and is acked; 50ms later it reads from a replica that lags by 200ms, so the read returns the old name and misses the client's own write
A client writes name=Alice to the primary and is acked; 50ms later it reads from a replica that lags by 200ms, so the read returns the old name and misses the client's own write

Traced anomaly: reading your own write and missing it

Async replication, replica lag ≈ 200ms, reads load-balanced across primary and replica.

tActionWhat the user sees
t0User sets display name to “Alice” → write to primary
t0+2msPrimary commits and acks; change starts replicating“Saved!”
t0+50msPage reloads; read is routed to a replica still 150ms behindold name — looks like the save was lost
t0+200msReplica finally applies the changecorrect on next read

Nothing is broken and no data is lost — the write is safely committed on the primary. The user simply read from a replica that hadn’t caught up. This is a read-your-writes violation, and it is the most common “the app feels buggy” symptom of async read replicas.

Fixes (buy back just enough consistency)

Pitfalls

How much does the fallback actually shift? Back-of-envelope: say writes are ~5% of operations and you route a user’s reads to the primary for a window T = 1 s after each of their own writes. Only reads that land in a 1 s window trailing a write hit the primary — on the order of ~5–10% of reads, not all of them, so the replicas still absorb the bulk of read traffic. The lever is T: a longer window catches more read-your-writes cases but pushes more read load back onto the primary and erodes the scaling you paid replicas for; a shorter T (or scoping the fallback to just the entity the user edited) keeps it. T is the correctness-vs-scaling dial — set it just long enough to cover typical replication lag, no longer.

The judgment layer

Synchronous (CP/EC) vs asynchronous (AP/EL). Choose synchronous when a stale read is a correctness bug — account balances, inventory counts, permission checks, anything a user edits and immediately re-reads — and you can afford the extra write latency and the risk of blocked writes when a replica is down. Choose asynchronous when the workload is read-heavy and latency-sensitive and bounded staleness is acceptable — social feeds, product catalogs, analytics — and patch the sharp edges (read-your-writes, monotonic reads) surgically rather than making every read consistent. In PACELC terms: Cassandra/Dynamo are PA/EL (available and fast, tunable toward consistency per query); Google Spanner and HBase are PC/EC (they hold consistency and pay the latency). The lens forces the question out into the open: what does this specific read do if it’s 200ms stale?

What about quorums?

With leaderless replication, N=3/W=2/R=2 makes every read set overlap the latest write set — but R+W>N alone is not linearizability: overlap guarantees the new value is present somewhere in your read set, yet concurrent writes, partially-failed writes, and read-repair timing can still let a later read observe an older value than an earlier read did. If you need linearizable reads from a quorum system you must add machinery — synchronous read repair on the read path, or routing through a leader/consensus. See quorum arithmetic: why R+W>N.

PACELC is per-configuration, not per-product

Cassandra at consistency ONE/ONE is PA/EL; the same cluster at QUORUM/QUORUM pays a round-trip to a majority on every operation and behaves close to PC/EC in normal operation. The stance lives in the settings you deploy, not in the product name.

Worked follow-up: route two reads

Catalog page — tolerates 200ms staleness, so route it to any replica. Cart after “add to cart” — needs read-your-writes, so serve it via an LSN token (a replica caught up past the user’s write) or from the primary. One routing rule per read path, chosen by what a stale value costs there.

Takeaways


Synthesized from Gilbert & Lynch (CAP proof), Daniel Abadi’s PACELC formulation, and Kleppmann, Designing Data-Intensive Applications (Ch. 5, replication lag and read-your-writes / monotonic reads). Re-authored/Deepened for this guide.

🤖 Don't fully get this? Learn it with Claude

Stuck on CAP/PACELC for Replication & Reads? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **CAP/PACELC for Replication & Reads** (System Design) and want to truly understand it. Explain CAP/PACELC for Replication & Reads from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **CAP/PACELC for Replication & Reads** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **CAP/PACELC for Replication & Reads** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **CAP/PACELC for Replication & Reads** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes