Deep-Read · DDIA · Chapter 5

Replication: One Dataset, Many Machines

Designing Data-Intensive Applications · Ch 5 · Martin Kleppmann · 2017

中文 →

What is this chapter about?

The data behind your bank app or online cart isn't stored on just one machine — it's copied several times and spread across different servers, data centers, even continents. DDIA Chapter 5 is about exactly that: why we copy data, how we copy it, and what goes wrong while copying. The technical name for "copying" here is replication.

Why keep several copies?

Three plain reasons. One: to survive failures. With a single copy, one crashed machine takes the whole site down; with three copies, lose one and two carry on. Two: to be close. If the data lives in the US, every request from Asia crosses half the planet — slow; keep a copy nearby instead. Three: to share the load. A hundred million people reading at once will crush one machine, so you copy the data ten times and let readers spread out.

The hard part isn't copying — it's keeping every copy in step

Copying a static file is trivial. The real headache is that data keeps changing. The moment you change your nickname, that change has to reach every copy. Copying takes time, which creates the most famous pitfall of all: right after you change something, other people may still see the old copy — like a letter that's been mailed but hasn't arrived yet. That gap is called replication lag.

Three ways to decide "who's allowed to change it"

If data can be changed, you must rule on who has the say, or chaos follows. This chapter gives three schemes, and the rest of the book rests on them:

① One machine has the say (single-leader). Pick one copy as the "master ledger"; every change goes there first, then it copies the change out to the others. Clean, no clashes — but if that master machine dies, you must hastily crown a stand-in, and that hand-over is where things most often go wrong.

② Several can change it, reconcile afterward (multi-leader). Each data center keeps a writable ledger; each edits locally and syncs with the others. Great for writing close to home — but if two people change the same cell at once, they conflict, like two people editing the same shared doc, and you must merge somehow.

③ No one's in charge, trust the crowd (leaderless). When you change something, tell several machines at once; when you read, ask several at once. As long as the machines you "wrote to" and the ones you "asked" overlap, you'll hit one that knows the latest — like sending an urgent notice to 3 colleagues, then asking any 2 later: you'll always reach someone in the know.

So which one should I use?

No free lunch: the harder you insist every copy be identical at every instant, the slower and less failure-tolerant you get; the more you chase speed and resilience, the more you must tolerate readers seeing stale data. Single-leader is simple and by far the most common (most databases default to it); multi-leader suits cross-region and offline work; leaderless is built to "keep running even if several machines are down." Choosing is really about which of fast / resilient / always-latest you want most.

Remember this one line

Replication = copying one dataset onto many machines — for fault tolerance, closeness, and read-sharing. The hard part isn't the copying, it's propagating changes, and coping when a reader hits a copy the change hasn't reached yet. Three schemes: one-machine-decides, several-reconcile, trust-the-crowd — each trading among fast / resilient / always-latest.

Want the actual mechanisms, the quorum notation, and diagrams? → Switch to the deep read