One leader, many followers
A newspaper has one editorial office where stories are written, and printing plants around the country that print copies. Every story goes through the office first; the plants receive it a few minutes later and print what they’ve received. Readers in any city get the paper from the nearest plant, a little behind the office.
Most databases work like this. One server, the leader (or primary), accepts all writes. It records every change in a log and sends the log to followers (replicas), which apply the same changes in the same order. Reads can go to any follower, so adding followers adds read capacity, and if the leader dies, a follower can take over.
Single-leader replication (PostgreSQL streaming replication, MySQL, MongoDB replica sets, most managed databases) ships the leader’s write-ahead log or a logical change stream to followers, which apply it in order. The key choices: synchronous acknowledgement (a write commits only after N followers confirm: no data loss on leader failure, higher latency, and writes block if the synchronous follower is down), asynchronous (fast, but followers lag and an unreplicated tail is lost on failover), or semi-synchronous (one synchronous follower, the rest async). Failover detects the dead leader (timeouts, so always a guess), promotes the most up-to-date follower, and redirects writes; the classic failure modes are lost writes and split brain, two nodes both accepting writes.
Single-leader replication
Tap a box to see what it does.
API servers
Send writes to the leader and most reads to followers. A database proxy or the driver usually does the routing.
Leader
Commits each write, appends it to its change log (WAL), and streams the log to the followers.
Follower A
The leader waits for this follower to confirm before acknowledging a write. It's always current, so failover to it loses nothing, but if it's slow, every write is slow.
Follower B
Applies the log as fast as it receives it. Usually milliseconds behind; seconds or minutes during load spikes or long transactions.
Follower C
A copy in another region for disaster recovery and local reads. Further behind because of the distance.
- Synchronous follower: the leader waits until it has the change. Safe, but slower.
- Asynchronous followers: the leader doesn’t wait. Fast, but they’re slightly behind: this delay is the replication lag.
- Failover: when the leader dies, a follower is promoted to leader. If it was asynchronous, the last few writes the old leader accepted but hadn’t sent yet are lost.
Predict the output
The leader acknowledges a payment write and crashes 30 ms later. Its only followers are asynchronous and were 80 ms behind. A follower is promoted. What happened to the payment?
With asynchronous replication, 'committed' only means committed on the leader. The payment was in the 80 ms of log the followers hadn't received, so the promoted follower never saw it: the client got a success, and the record is gone. If the old leader comes back, its extra writes conflict with the new history and are usually discarded. That's why money and other must-not-lose data use at least one synchronous replica (or a consensus-based database), accepting slower writes.
Failover and split brain
Failure detection is a timeout, so it can’t distinguish a dead leader from a slow or partitioned one. If the old leader is alive on the other side of a partition and keeps accepting writes after a follower was promoted, two leaders diverge: split brain. Defenses:
- Consensus for leadership (Raft or Paxos in etcd, ZooKeeper, Patroni, managed services): a new leader needs a majority, and a minority side can’t elect one.
- Fencing tokens: every leader term gets an increasing number; storage rejects writes carrying an older term, so a stale leader’s writes fail even if it doesn’t know it’s been replaced.
- Lease-based leadership: a leader stops accepting writes when its lease expires, before a new leader may be elected (requires bounded clock drift).
Timeouts are a trade-off: too short and load spikes trigger needless failovers (which add load); too long and outages last longer.
- Single leader ships its log to followers. Sync: no loss, higher latency, writes block on follower failure. Async: fast, lag, loses the unreplicated tail on failover. Semi-sync as the usual compromise.
- Failure detection is a timeout guess; failover risks lost writes and split brain.
- Prevent split brain with consensus-based leadership, fencing tokens on writes, or leases with bounded clock drift.
Check this part
In leader-follower replication, where do writes go?
What is replication lag?
What prevents a deposed leader from accepting writes after a partition?