Designbench

Lesson 3.3 · 15 min

Replication

Crash a leader under async, semi-sync and sync replication and count the acknowledged writes that vanish, then tune a leaderless quorum.

The idea in plain words

Replication keeps copies of the same data on several machines, like keeping photocopies of important papers in different buildings. If one building burns down, nothing is lost, and more people can read at once.

The problem it solves

If your data lives on one machine, losing that machine loses the data, and that machine is the limit on how many reads you can serve.

How it works

  1. One copy is the primary: it accepts all writes.
  2. It sends each change to the other copies (replicas), which apply them in the same order.
  3. Reads can go to replicas to spread the load.
  4. The primary can wait for replicas to confirm a write (safer, slower) or not wait (faster, but a crash can lose the newest writes).
  5. If the primary dies, a replica is promoted to take over (failover).

Example

A primary and two replicas. With asynchronous replication, the primary says “saved” right away; if it crashes a second later, a write that hadn’t reached the replicas is gone, even though the user saw success. With synchronous replication, “saved” means a replica has it too, at the cost of slower writes.

Key terms

Primary (leader)
The copy that accepts writes and sends them to the others.
Replica (follower)
A copy that receives changes from the primary and can serve reads.
Synchronous
The primary waits for replicas to confirm before telling the client “saved”.
Asynchronous
The primary confirms at once and sends changes later, so a crash can lose the latest writes.
Failover
Promoting a replica to primary when the primary dies.
Split brain
Two nodes both acting as primary at once, accepting conflicting writes.

In this lesson you'll learn

Sections

  1. Theory: crash the leader
  2. Theory: who accepts writes
  3. Theory: quorums
  4. Design: pick a setup
  5. Check yourself

Cheat sheet

Asyncfast; a crash can lose acked writes
Semi-syncno loss if you promote the acker
Sync to allone dead follower blocks writes
QuorumR + W > N; survives N − W down
Failoverpromote freshest, fence the old leader

The interactive simulations and the quiz load with JavaScript.