System design concepts · Data That Doesn't Break

Database Replication Explained: Leader-Follower, Multi-Leader, Leaderless

Replication keeps the same data on several machines: for survival when one dies, for more read capacity, and for being close to users. The hard part is keeping the copies honest.

What you'll be able to explain
  • Compare single-leader, multi-leader and leaderless replication
  • Choose synchronous vs asynchronous replication
  • Handle replica lag: read-your-writes and monotonic reads
  • Explain failover and split brain
  • Use quorums (W + R > N)

Three topologies

SERVICEAppDATABASELeaderreads + writesDATABASEFollower 1readsDATABASEFollower 2readswritesreadschange logchange log
Single-leader: all writes go to the leader, which streams changes to followers.
Topology Writes go to Pros Cons Used by
Single-leader One leader Simple, no write conflicts Leader is a write bottleneck; failover needed PostgreSQL, MySQL, MongoDB
Multi-leader Several leaders (e.g. one per region) Local writes in every region Write conflicts must be resolved Multi-region setups, collaborative apps
Leaderless Any replica (quorums) No failover, high availability Weaker consistency, read repair needed Cassandra, DynamoDB-style stores

Synchronous or asynchronous?

  • Synchronous: the leader waits for a follower to confirm before acknowledging the client. No data loss if the leader dies, but slower writes, and a slow follower stalls everything.
  • Asynchronous: acknowledge immediately, replicate in the background. Fast, but the last few writes can be lost on failover.
  • Semi-synchronous (common in practice): wait for one follower synchronously, the rest async.
Tip

In interviews, link this to RPO: "For orders we need RPO ≈ 0, so I'll use semi-synchronous replication to a standby in another availability zone. Read replicas can be async."

Living with replica lag

Async followers trail the leader by milliseconds, or by seconds under load. This creates three classic anomalies:

  1. Read-your-writes: you update your profile, refresh, and see the old version (the read went to a lagging replica). Fix: read your own data from the leader for a short window after writing, or pass the write's log position and read from a replica that has caught up.
  2. Monotonic reads: you see a comment, refresh, and it disappears (second read hit a more-lagged replica). Fix: pin each user to one replica (hash user ID).
  3. Consistent prefix: you see an answer before its question. Fix: keep causally related writes in the same partition, or track causality.
UserLeaderReplica1update name = "Ananya"2ok3GET profile4name = "Anu" (stale!)5replicate (arrives 400 ms later)
Read-your-writes violation caused by replica lag.