How it works
Teams replicate data for three reasons: to survive a machine failure, to serve more reads, and to put data closer to users. Making a copy is easy; keeping it current as data changes is the hard part. In single-leader replication, one node, the leader (or primary), accepts all writes and records them in a replication log. Followers (or replicas) apply the log in the same order, so they converge on the same state. Postgres, MySQL, and MongoDB replica sets work this way. The cost is that every write still passes through one node.
The key decision is when the leader tells a client that a write succeeded. With synchronous replication it waits for followers to confirm. With asynchronous replication it answers after its own commit, and followers catch up later. Semi-synchronous replication sits between: it waits for some followers, often one.
Take an example leader with one follower 1 ms away and another 90 ms away. Asynchronous commits wait for neither, but a leader crash loses whatever has not shipped. Waiting for both adds at least 90 ms to every commit, and if either follower stalls, all writes stall. Waiting for any one of them adds about 1 ms, and a write survives the leader’s death as long as the follower that confirmed it also survives. One caveat: MySQL’s semi-synchronous mode falls back to asynchronous after a timeout, so the guarantee can lapse quietly unless you monitor for it.
A payments ledger has a leader, two followers in the same region (1 ms away), and one follower in another region (90 ms away). The requirements: no acknowledged payment is lost if the leader’s machine dies, and p99 write latency stays under 20 ms. Which acknowledgment rule do you choose, and what do you tell the business it does not cover?
Wait for any one of the two nearby followers, and replicate asynchronously to the distant one. This survives the leader’s machine dying within the latency budget, provided failover promotes a follower that has the write. Tell the business what it does not cover: losing the whole region can lose writes that had not yet reached the distant follower. Closing that gap means waiting 90 ms on every commit, which breaks the budget.
Use this as a guide for self review; written answers are not graded.Keep in mind
- One leader gives every change a single order, but all writes still pass through one node.
- Waiting for followers trades latency and availability for a smaller chance of losing an acknowledged write.
- Waiting for any one of several followers guarantees an extra copy without letting one slow follower block commits.