CMD Guide
HomeSystem DesignReplication

What is Replication

Replication keeps several copies of one dataset in agreement by funnelling every write through a single authoritative copy (the leader), recording each committed change as an ordered stream of records — the replication log — which every follower pulls and replays in the same order, so any copy can serve reads and any copy can take over when another dies. The whole idea reduces to that one mechanism: an ordered log, replayed everywhere, drives the copies to the same state.

Concretely, the leader appends each committed change to its write-ahead log at a monotonically increasing offset; every follower keeps a cursor into that log and applies records up to its current offset. The gap between the leader's newest offset and a follower's applied offset is the replication lag. That single mechanism buys three distinct things: availability (a copy survives a node loss), read scale-out (spread reads across copies), and locality (place a copy next to the reader).

Redundancy vs. replication

They are related but not synonyms. Redundancy is the goal — eliminate single points of failure by having more than one of something. Replication is one mechanism that delivers data redundancy, and its defining trait is that copies are kept in sync continuously, in near-real-time — not snapshotted every few hours the way a backup is.

RedundancyReplication
What is duplicatedComponents / capacity (nodes, disks, power)The dataset itself
FreshnessMay sit idle as spare (cold or hot standby)Tracks the leader continuously via the log
Primary useSurvive hardware failureHigh availability + read scaling + locality

Note the nuance: a replica can be active (serving reads) or a passive hot standby (kept current but idle until promoted). So the popular line "replication is active, all copies are utilized" is too strong — whether a copy serves traffic is a deployment choice; the trait that actually defines replication is continuous synchronization.

diagram
diagram

Sync, async, semi-sync: it is all about when the client hears "OK"

The three replication modes differ in exactly one decision: how many followers must acknowledge a write before the leader reports it committed to the client. Everything else — durability, write latency, blast radius of a slow node — follows from that.

diagram
diagram

Worked example: one profile update, traced

Topology: leader in us-east; follower A in the same AZ (network ~0.5 ms one-way); follower B in eu-west (~40 ms one-way over the WAN). A user runs UPDATE users SET bio = 'hi' WHERE id = 42. Here is the async timeline, step by step.

t (ms)WhereEventOffsets after
0.0client → leaderWrite request arrivesleader head 4820
0.3leaderWrites WAL, commits locally, appends record at offset 4821leader 4821
0.5leader → clientReturns 200 OK (async: no wait) — client now believes the write is durableleader 4821
1.0follower AReceives record 4821 over LAN, replays itA 4821 (lag ~0.5 ms)
40.0follower BReceives record 4821 over WAN, replays itB 4821 (lag ~40 ms)

Between t = 0.5 ms and t = 40 ms, follower B still serves the old bio. A European user routed to B who reads right after writing sees their change "missing" — the classic read-your-writes anomaly (mechanics and fixes are covered on Replication Lag & Failover). The same write under the three modes:

ModeClient acked atLost if leader crashes nowEffect of a slow / dead follower B
Async~0.5 msUp to ~40 ms of writes not yet shipped (RPO > 0)None — B just falls further behind
Semi-sync (k=1, A local)~1.3–1.5 ms (0.3 commit + 0.5 out + 0.5 ack back)~0 — A already has itNone — B stays async
Sync (all)~80 ms (0.3 ms commit + 40 ms ship to eu-west + 40 ms ack back)0Every write stalls; B down ⇒ writes halt entirely

Note the ack is a round trip: sync-to-eu-west costs ~80 ms, twice the 40 ms one-way shipping time the async table row shows — a follower having the write and the leader knowing it has it are separated by the return leg. For any topology, synchronous ack time ≈ local commit + 2 × one-way latency to the slowest required follower (plus its apply time).

Pitfalls

When to use it — and when not

Reach for replication when you see these signals: read traffic dwarfs writes (spread reads across copies); you cannot tolerate a single node's death (keep a hot standby to promote); or readers are geographically spread (put a copy near them). Then pick the mode by what you cannot afford to lose:

Trade-offs vs. named alternatives

Rule of thumb: replicate for availability and read scale; partition for write scale and capacity; stay single-node while you honestly can.

Takeaways


Sources: Martin Kleppmann, Designing Data-Intensive Applications, ch. 5 (Replication) — leaders, followers, replication logs, sync vs. async, and lag; PostgreSQL documentation on streaming replication and synchronous_commit; MySQL documentation on semisynchronous replication (rpl_semi_sync) and its timeout fallback. Re-authored / deepened for this guide; lag anomalies, failover, split-brain, and fencing are treated on the companion page "Replication Lag & Failover."

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

Stuck on What is Replication? 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 **What is Replication** (System Design) and want to truly understand it. Explain What is Replication 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 **What is Replication** 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 **What is Replication** 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 **What is Replication** 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