Replication

Intermediate · 19 min read · High-Level Design, Storing Data

Leader-follower, multi-leader and leaderless replication, replication lag and failover.

Replication means keeping copies of the same data on multiple machines. It's one of the two fundamental ways to distribute data (the other is partitioning, covered next), and nearly every production database uses it.

Replication serves three purposes:

Synchronous vs asynchronous replication

Fully synchronous replication to every follower is impractical — any single slow node stalls all writes. The common compromise is semi-synchronous: one follower is synchronous, the rest asynchronous. That guarantees the data exists on at least two nodes while keeping latency reasonable.

Single-leader replication

The most common model (PostgreSQL, MySQL, MongoDB replica sets, Redis, Kafka partitions).

Multi-leader replication

Multiple nodes accept writes, and each replicates its changes to the others.

Leaderless replication

There is no leader: clients (or a coordinator node) send writes to several replicas directly and read from several replicas. Popularised by Amazon's Dynamo paper and used in Cassandra, ScyllaDB and Riak.

Comparing the three models

How replication logs are shipped

Interview questions

  • A user updates their profile photo and immediately sees the old one. Why, and how would you fix it?
  • What is split brain and how do systems prevent it?
  • With N=3, W=2, R=2, can a read ever return stale data?
  • When would you choose multi-leader replication?

Practice

Write your answer before opening the suggested one. If you mark it "Partly" or "Missed it", it comes back in your review deck.

Further reading

Key takeaways

  • Replication provides availability, read scaling and geographic locality.
  • Synchronous replication protects data but adds latency; asynchronous is fast but can lose recent writes on failover. Semi-sync is a common compromise.
  • Single-leader is the default; plan for replication lag (read-your-writes, monotonic reads) and careful failover (split brain, fencing).
  • Multi-leader suits multi-region and offline writes but requires conflict resolution.
  • Leaderless systems use quorums (W + R > N), read repair and anti-entropy to converge.

Previous: Transactions, Isolation & MVCC · Next: Partitioning & Sharding