← Back to System Design, page 1

system-design-0011 · Medium mid

Compare single-leader, multi-leader and leaderless replication, and synchronous versus asynchronous replication.

Single-leader sends all writes to one node that streams changes to followers. Multi-leader accepts writes at several nodes, often one per region, and must resolve conflicts. Leaderless lets clients write to several replicas and read with quorums. Synchronous replication waits for replicas before confirming a write (safer, slower); asynchronous confirms immediately (faster, can lose recent writes on failover).

Full answer

Why replicate

Replication keeps copies of the same data on several machines for three reasons: survive machine loss, serve more reads, and put data closer to users.

Single-leader (primary-replica)

All writes go to the leader. It writes to its log and ships changes to followers, which apply them in order. Reads can go to the leader (fresh) or followers (possibly behind).

  • Simple, no write conflicts, easy to reason about.
  • Write throughput is limited by one node.
  • Failover needs care: detect the failed leader, promote the most up-to-date follower, redirect clients, and stop the old leader from accepting writes if it comes back (split brain).

PostgreSQL streaming replication and MySQL replication work this way.

Multi-leader

Several nodes accept writes, usually one per data centre, and replicate to each other. Writes are fast locally and each region survives alone. The cost is write conflicts: two regions update the same row at the same time. You need a rule: last-writer-wins (simple, silently drops one update), merge functions, CRDTs, or routing each record's writes to a "home" region. Also used by offline-first apps where each device is a leader.

Leaderless

Clients (or a coordinator) send each write to N replicas and consider it done when W acknowledge. Reads ask R replicas and take the newest version. With R + W > N, every read set overlaps every write set, so at least one replica in the read has the latest write. Example: N = 3, W = 2, R = 2. Repair happens through read repair and background anti-entropy. Cassandra and Dynamo-style stores use this model.

Synchronous versus asynchronous

  • Synchronous: the leader waits for follower acknowledgement. No acknowledged write is lost if the leader dies, but one slow follower slows every write.
  • Asynchronous: the leader confirms immediately. Fast, but on failover the newest writes may be missing.
  • Semi-synchronous: wait for one follower, the rest async. A common middle ground.

Choosing

Single-leader with one synchronous and some async followers is the default for most relational workloads. Multi-leader fits multi-region writes or offline clients when conflicts can be resolved. Leaderless suits very high write volume with tunable consistency and tolerance for some anomalies.

By level

Fresher: Explain leader and follower roles, why we keep copies, and what happens if followers are a little behind. One simple diagram of a leader and two followers is enough.

Mid: Compare the three models, explain the quorum rule with numbers, discuss failover steps and sync versus async durability. Expect the quorum rule with numbers such as N = 3, W = 2, R = 2.

Senior: Discuss split brain and fencing, conflict resolution with CRDTs or version vectors, sloppy quorums and hinted handoff, cross-region replication cost, and RPO and RTO targets. It should state recovery point and recovery time targets for the chosen setup.

Key points

  • Replication gives fault tolerance, read scaling and locality
  • Single-leader has no write conflicts but needs careful failover
  • Multi-leader needs a conflict resolution strategy
  • Leaderless uses quorums: R + W > N gives overlapping read and write sets
  • Async replication can lose the latest writes on failover

Common mistakes

  • Saying async replication never loses data
  • Ignoring split brain during failover
  • Using last-writer-wins without accepting silent data loss
  • Claiming R + W > N gives full linearizability in all cases

Follow-ups

  • How do you prevent split brain when promoting a new leader?
  • What happens to quorum reads when two of three replicas are down?
  • How would you resolve conflicting edits to a shared document in a multi-leader setup?

Tips

  • Draw the write path for each model in one line
  • State the quorum condition with a numeric example
  • Mention a real database for each model

Evaluation rubric

  • Correctly describes all three models
  • Explains sync versus async and data-loss implications
  • Covers conflicts and failover issues
  • Recommends a model for a stated workload