AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content
SD notes

System Design · Note 6 of 22

Database Replication

Intermediate · 7 min read · updated 29 October 2026

Quick answer

What is database replication in system design?

Database replication keeps copies of the same data on several machines. Usually one leader accepts writes and ships them through a log to followers, which serve reads and can take over if the leader fails. Replication adds read capacity and availability, at the cost of lag between copies and harder failure handling.

On this page
  1. Leader–follower replication
  2. Synchronous vs asynchronous
  3. Replication lag and stale reads
  4. Failover
  5. Other topologies
  6. Interview questions
  7. Common questions

Replication means keeping the same data on more than one machine, so the database survives failures and can serve more reads.

Leader–follower replication

  • One node is the leader (primary); only it accepts writes.
  • It records every change in a replication log (binlog, WAL).
  • Followers (replicas) replay the log in order and serve reads.
  • More followers = more read capacity — but not more write capacity.
Leader–follower: writes go to the leader, reads spread over followers

An app sends writes (W) and reads (R). One node is the leader; the followers keep copies of its data by replaying its log.

0:01 / 0:24Step 1 of 8
Transcript · 8 steps

Synchronous vs asynchronous

SynchronousAsynchronous
Client hears OKAfter a follower confirmsAfter the leader commits
Write latencyHigherLower
Leader crashWrite is safe on a followerRecent writes can be lost
A slow followerStalls writesJust lags
  • Semi-synchronous is the common middle: wait for one follower, ship to the rest asynchronously.
Synchronous vs asynchronous replication: when the client hears OK

The same write under both policies. Delays here are illustrative: 1 ms each way between client and leader, 2 ms between leader and follower.

0:01 / 0:16Step 1 of 5
Transcript · 5 steps

Replication lag and stale reads

  • Async followers trail the leader by a lag — milliseconds normally, longer under load.
  • A read from a lagging follower returns old data: eventual consistency.
  • The painful case: a user does not see their own write.
  • Fixes:
  • Read-your-writes: send a user's reads to the leader for a while after they write.
  • Position-aware reads: read only from followers past the user's last write.
  • Monotonic reads: pin each user to one follower so time never goes backwards.
Replication lag: a user reads their own write from a stale follower

A user's profile says name = Ana on the leader and on its follower. Reads are sent to the follower to keep load off the leader.

0:01 / 0:18Step 1 of 6
Transcript · 6 steps

Failover

  • Detect: no heartbeat from the leader within a timeout.
  • Elect: promote the follower with the most up-to-date log.
  • Reconfigure: clients and other followers switch to the new leader.
  • Risks:
  • Lost writes with async replication — the old leader's unshipped entries.
  • Split brain: two leaders accepting writes; prevent with a majority vote and fencing.
  • Too short a timeout fails over on a slow but healthy leader.
Failover: the most up-to-date follower is promoted

Node B leads and has log entries up to 6. Its followers replay the log asynchronously and trail it: Node A is at 5, Node C is at 4.

0:01 / 0:15Step 1 of 5
Transcript · 5 steps

Other topologies

  • Multi-leader: a leader per region; writes are local, but concurrent writes conflict and need resolving.
  • Leaderless (Dynamo-style): write to W replicas, read from R; with W + R > N a read overlaps the latest write.
  • The trade-offs between consistency and availability are the subject of the CAP theorem.

Interview questions

  • Does replication help write-heavy systems? No — every replica applies every write; split the data with sharding instead.
  • A user updates their profile and sees the old one. Why? The read hit a lagging follower; route their reads to the leader after a write.
  • Sync or async replication for payments? At least one synchronous follower, so an acknowledged payment survives losing the leader.
  • How does failover go wrong? Lost async writes, split brain, or flapping on a timeout that is too short.

Next: Database Sharding · Before this: Content Delivery Networks

Common questions

Why do we replicate a database?

For availability, so a failed machine does not take the data offline; for read scaling, since followers serve reads; and for latency, by placing a copy near users in another region. Replication does not add write capacity, because every copy still applies every write.

What is the difference between synchronous and asynchronous replication?

With synchronous replication the leader waits for a follower to confirm a write before telling the client it succeeded, so the write survives a leader crash but every write is slower. With asynchronous replication the leader answers at once and ships the write later, which is faster but can lose acknowledged writes on failover.

What is replication lag?

The delay between a write committing on the leader and a follower applying it. It is often small but grows under heavy load, long transactions or network trouble, and while it lasts a read from that follower returns old data.

How do you guarantee read-your-writes consistency?

Route a user's reads to the leader for a short window after that user writes, or remember the log position of the user's last write and only read from followers that have reached it. Other users can still read from any follower.

What is split brain?

Two nodes both believing they are the leader and both accepting writes, usually after a network partition or a failover while the old leader was only slow. Their histories diverge. Systems prevent it with a majority vote or consensus to elect a leader and by fencing the old one off.

What are multi-leader and leaderless replication?

Multi-leader lets several nodes accept writes, often one per region, and syncs them, so concurrent writes can conflict and need resolving. Leaderless systems such as Cassandra and DynamoDB-style stores write to several replicas at once and read from several, using quorums so reads overlap the latest writes.

Database Replication: Leader-Follower, Sync vs Async

Database replication for system design interviews: leader-follower, synchronous vs asynchronous, replication lag, read-your-writes and failover, animated.

  • Subject: System Design
  • Level: Intermediate
  • Reading time: 7 min
  • Updated: 2026-10-29

What is database replication in system design?

Database replication keeps copies of the same data on several machines. Usually one leader accepts writes and ships them through a log to followers, which serve reads and can take over if the leader fails. Replication adds read capacity and availability, at the cost of lag between copies and harder failure handling.

Replication means keeping the same data on more than one machine, so the database survives failures and can serve more reads.

Leader–follower replication

  • One node is the leader (primary); only it accepts writes.
  • It records every change in a replication log (binlog, WAL).
  • Followers (replicas) replay the log in order and serve reads.
  • More followers = more read capacity — but not more write capacity.
AppR4 read x = 8Leaderx = 8Follower 1x = 8Follower 2x = 8replication
Leader–follower: writes go to the leader, reads spread over followers.
  1. An app sends writes (W) and reads (R). One node is the leader; the followers keep copies of its data by replaying its log.
  2. W1 (x = 5) goes to the leader, the only node that accepts writes. It applies it and appends it to its log.
  3. R1 goes to Follower 1, chosen round robin, and reads x = 5. Reads never touch the leader. The leader ships W1 to both followers, which apply it in log order, so every node holds x = 5.
  4. R2 goes to Follower 2 and reads x = 5. Each follower adds read capacity, which is why read-heavy systems replicate.
  5. W2 (x = 8) goes to the leader, the only node that accepts writes. It applies it and appends it to its log.
  6. R3 reads x = 8 from Follower 1; round robin keeps alternating between the two followers. The leader ships W2 to both followers, which apply it in log order, so every node holds x = 8.
  7. R4 reads x = 8 from Follower 2; round robin keeps alternating between the two followers.
  8. All 6 requests are done: 2 writes went to the leader and 4 reads were shared by the followers.

Synchronous vs asynchronous

SynchronousAsynchronous
Client hears OKAfter a follower confirmsAfter the leader commits
Write latencyHigherLower
Leader crashWrite is safe on a followerRecent writes can be lost
A slow followerStalls writesJust lags
  • Semi-synchronous is the common middle: wait for one follower, ship to the rest asynchronously.
SynchronousClientLeaderFollowerwritereplicateackOKOK at 6 msAsynchronousClientLeaderFollowerwriteOKOK at 2 msnever sentleader crashes
Synchronous vs asynchronous replication: when the client hears OK.
  1. The same write under both policies. Delays here are illustrative: 1 ms each way between client and leader, 2 ms between leader and follower.
  2. Synchronous: the leader sends the write to the follower and waits. Asynchronous: the leader answers OK at once, at 2 ms.
  3. The follower acknowledges the synchronous write. The asynchronous leader ships its write in the background, after the client was already told it succeeded.
  4. The synchronous client hears OK at 6 ms, 4 ms later than the async one, but the write is now on two machines.
  5. The risk: had the async leader crashed before shipping the write, the client holds an OK for data no follower has. A promoted follower would not have it.

Replication lag and stale reads

  • Async followers trail the leader by a lag — milliseconds normally, longer under load.
  • A read from a lagging follower returns old data: eventual consistency.
  • The painful case: a user does not see their own write.
  • Fixes:
  • Read-your-writes: send a user's reads to the leader for a while after they write.
  • Position-aware reads: read only from followers past the user's last write.
  • Monotonic reads: pin each user to one follower so time never goes backwards.
LeaderFollowerAnaAnyaAnaAnyawrite name = Anyalag 250 msRfrom leader: AnyaRfrom follower: Anya0 ms100 ms200 ms300 ms400 ms500 ms
Replication lag: a user reads their own write from a stale follower.
  1. A user's profile says name = Ana on the leader and on its follower. Reads are sent to the follower to keep load off the leader.
  2. At 50 ms the user changes their name to Anya. The leader commits it and replicates asynchronously; this follower is 250 ms behind (illustrative).
  3. At 150 ms the page reloads and reads from the follower, which still says Ana. The user's own change seems to have vanished: a stale read.
  4. At 300 ms the follower applies the write. Replication lag is usually short, but it grows under load or after a network blip.
  5. At 400 ms a read from the follower returns Anya. The data converged: this is eventual consistency.
  6. Read-your-writes fix: for a short while after a user writes, send that user's reads to the leader. The read at 150 ms then returns Anya.

Failover

  • Detect: no heartbeat from the leader within a timeout.
  • Elect: promote the follower with the most up-to-date log.
  • Reconfigure: clients and other followers switch to the new leader.
  • Risks:
  • Lost writes with async replication — the old leader's unshipped entries.
  • Split brain: two leaders accepting writes; prevent with a majority vote and fencing.
  • Too short a timeout fails over on a slow but healthy leader.
AppNode A12345leader · log 5Node B123456rejoins · log 6Node C12345follower · log 5
Failover: the most up-to-date follower is promoted.
  1. Node B leads and has log entries up to 6. Its followers replay the log asynchronously and trail it: Node A is at 5, Node C is at 4.
  2. Node B crashes. Its entry 6 was acknowledged to a client, but no follower has received it yet.
  3. The followers stop hearing heartbeats. After a timeout they compare log positions, Node A 5 and Node C 4, and pick the most up to date.
  4. Node A is promoted to leader and the app's writes go to it. Node C now follows Node A and catches up to entry 5.
  5. Node B returns as a follower of Node A and must discard entry 6, which nobody else has: 1 acknowledged write lost. Synchronous replication to one follower prevents that.

Other topologies

  • Multi-leader: a leader per region; writes are local, but concurrent writes conflict and need resolving.
  • Leaderless (Dynamo-style): write to W replicas, read from R; with W + R > N a read overlaps the latest write.
  • The trade-offs between consistency and availability are the subject of the CAP theorem.

Interview questions

  • Does replication help write-heavy systems? No — every replica applies every write; split the data with sharding instead.
  • A user updates their profile and sees the old one. Why? The read hit a lagging follower; route their reads to the leader after a write.
  • Sync or async replication for payments? At least one synchronous follower, so an acknowledged payment survives losing the leader.
  • How does failover go wrong? Lost async writes, split brain, or flapping on a timeout that is too short.

Next: Database Sharding · Before this: Content Delivery Networks

Common questions

Why do we replicate a database?

For availability, so a failed machine does not take the data offline; for read scaling, since followers serve reads; and for latency, by placing a copy near users in another region. Replication does not add write capacity, because every copy still applies every write.

What is the difference between synchronous and asynchronous replication?

With synchronous replication the leader waits for a follower to confirm a write before telling the client it succeeded, so the write survives a leader crash but every write is slower. With asynchronous replication the leader answers at once and ships the write later, which is faster but can lose acknowledged writes on failover.

What is replication lag?

The delay between a write committing on the leader and a follower applying it. It is often small but grows under heavy load, long transactions or network trouble, and while it lasts a read from that follower returns old data.

How do you guarantee read-your-writes consistency?

Route a user's reads to the leader for a short window after that user writes, or remember the log position of the user's last write and only read from followers that have reached it. Other users can still read from any follower.

What is split brain?

Two nodes both believing they are the leader and both accepting writes, usually after a network partition or a failover while the old leader was only slow. Their histories diverge. Systems prevent it with a majority vote or consensus to elect a leader and by fencing the old one off.

What are multi-leader and leaderless replication?

Multi-leader lets several nodes accept writes, often one per region, and syncs them, so concurrent writes can conflict and need resolving. Leaderless systems such as Cassandra and DynamoDB-style stores write to several replicas at once and read from several, using quorums so reads overlap the latest writes.

← Content Delivery Networks (CDN) · Database Sharding →