SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Indexing
  • Partitioning
  • Replication
  • Sharding
  • Query Optimization
  • Denormalization
  • Materialized Views
  • Connection Pooling
  • Replication Models
  • Replication Lag
  • Quorum (R + W > N)
  • Shard Keys, Hot Shards and Resharding
  • Cross-Shard Joins
  • Backups, RPO, RTO and Disaster Recovery
  • Point-in-Time Recovery
  • Data Archiving and TTL
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Database Scaling

Replication Models

Leader-follower, multi-leader and leaderless: who is allowed to accept a write?

⏱ 16 min readAdvancedMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Every replicated database must answer one question: who is allowed to accept a write? There are three main answers, and each one changes how the system behaves when things go wrong.

  • Single-leader: one node takes all writes and the others copy it. Simple, and no write conflicts.
  • Multi-leader: several nodes take writes (for example one per region) and copy each other. Fast local writes, but two leaders can change the same thing at once, so conflicts must be solved.
  • Leaderless: any node can take a write. The client writes to several nodes and reads from several, using a quorum.

02Concept: What is it?

The page on Replication explains why we keep copies. This page goes one step deeper: how are the copies kept in step? The answer depends on who may write.

In single-leader replication, all writes go to one node, the leader. It puts them in one order in its log, and the followers replay that log. Because there is a single place that decides the order, every copy ends up the same.

In multi-leader replication, each region has its own leader. A user in Europe writes to the EU leader and a user in the US writes to the US leader, so both are fast. The leaders then send their writes to each other. If two users change the same row at the same time, the leaders disagree, and the system needs a rule to settle it.

In leaderless replication, there is no special node. A client (or a coordinator node) sends each write to several replicas and reads from several replicas. If enough of them answer, the operation counts as done. The rule for "enough" is a quorum.

Three shapes
Single-leader
👑Leaderall writes
↓log
📋F1
📋F2
Multi-leader
👑EU leader
↔
👑US leader
⚠️conflicts to resolve
Leaderless
🧑‍💻Client
↓write to W, read from R
🟡N1
🟡N2
🟡N3
Arrows show who sends changes to whom. Dashed arrows mean writes that can conflict.
🧠The big trade
The more places that can take a write, the faster and more available writing becomes, and the more you must work to keep the copies from disagreeing.

03Real-Life Example

🍵Editing a Shared Menu in Three Restaurants
A restaurant chain keeps its menu in a book at every branch. In the first plan, only head office may change the menu, and it posts the new pages to all branches. Every book is the same, but a branch cannot change a price itself, even when the phone line to head office is down. In the second plan, each city manager may edit the menu, and they mail changes to each other. Now two managers may change the same dish on the same day, and someone must decide which price wins. In the third plan, any waiter may edit any copy, and a change counts once at least three of five books have it. It always works, but different books may briefly show different prices.
Menu books
Replication models
Only head office edits, branches copy
Single-leader
Each city manager edits and mails changes
Multi-leader
Any waiter edits any book
Leaderless
Two managers change the same dish
A write conflict
Rule: the later change wins
Last-write-wins (LWW)
Rule: combine both changes
Merge (for example a CRDT)
Check that 3 of 5 books have the change
Quorum
Compare books and fix any that differ
Read repair and anti-entropy

04Why Do We Need It?

🧭Pick by your needs
The model decides where writes can happen, how conflicts are handled, and how the system fails.
🌍Write near the user
Multi-leader lets each region accept writes with local latency.
🛡️No single leader to lose
Leaderless keeps accepting writes when some nodes are down.
📏Simplicity has value
Single-leader avoids write conflicts entirely. Most apps should start there.
🔎Know the failure modes
Failover, split brain, conflicts and stale reads all depend on the model.
🗣️A classic interview topic
You are often asked to compare the three and say when each fits.
One writer is simple. Many writers are fast and available, but you must settle disagreements.

05Where Do We Use It?

🐘Single-leader
PostgreSQL, MySQL, SQL Server and MongoDB replica sets all work this way by default.
🌐Multi-leader
Used for multi-region setups, and by some databases for active-active data centres. Also the shape of an offline-first app, where each device is a leader.
📝Collaborative editing
Many people editing one document is multi-leader in spirit, and uses merge rules such as CRDTs or Operational Transformation.
🪐Leaderless
Dynamo-style stores such as Cassandra and Riak (and DynamoDB in its own managed form) spread copies with quorum reads and writes.
📨Message logs
Kafka partitions have one leader each, a single-leader model per partition.
☁️Managed cloud databases
Offer a leader with read replicas, and sometimes a multi-region option with conflict rules.

06Types / Parts / How It Works

Single-leader: sync, async and failover

ModeLeader waits forEffect
AsynchronousNothingFast. A leader crash can lose the newest confirmed writes, and followers can lag.
Semi-synchronousOne followerA second copy of every confirmed write exists. A common middle choice.
SynchronousAll followersSafest, but one slow or dead follower stalls every write.

When the leader fails, a follower must be promoted. The system detects the failure (missed heartbeats), picks the most up-to-date follower, redirects clients, and must stop the old leader from accepting writes if it comes back. If it does not, you get a split brain.

Multi-leader: how to settle a conflict

RuleHow it worksWatch out
Avoid conflictsRoute all writes for one record to the same leader (for example by user's home region)Breaks down when that region is down or the user travels
Last write wins (LWW)Keep the value with the latest timestampClocks are never perfect, and the losing write is silently thrown away
MergeCombine both values with a rule that always gives the same answer on every node (CRDTs)Only works when the data type can be merged
Keep both and askStore both versions as siblings, and let the application or the user chooseThe application must handle the extra work
Multi-leader topologies
Circular
L1
→↓
L2
→↓
L3
Star
Hub
L2
L3
L4
All-to-all
L1
↔
L2
↔
L3
How leaders pass writes to each other. More links mean faster spread but more ways for writes to arrive in odd orders.

Leaderless: how copies get repaired

  • Read repair: when a read finds that one replica has an old value, the client writes the newer value back to it.
  • Hinted handoff: if a replica is down, another node keeps the write as a "hint" and hands it over when the replica returns.
  • Anti-entropy: a background process compares replicas and copies the missing data. It often uses Merkle trees to find the differences quickly.
  • Gossip: nodes pass news of who is alive and who is down to each other.
VisualizerWho takes the write, and what happens on a clash?Choose a model, press one write, then press the two-writers button. In multi-leader, flip between Last write wins and Merge. In leaderless, look at the sibling values.
Replication model
Single-leader: what each replica holds after the write (before any write)
Replica A
Leader
x = 0
Replica B
Follower
x = 0
Replica C
Follower
x = 0
Who takes writes
1 node
Write conflicts
-
one place orders writes
Replicas agree?
yes
Three replicas hold x = 0. Pick a model, then press a write button.

A simplified story with fixed outcomes and no random numbers. Real systems also use clocks, version vectors and background repair. Last-write-wins depends on clocks, which can be wrong by a little, so it can drop the "wrong" write.

07How to Use It / Steps / Implementation

Choosing a model

  1. 1
    Start with single-leader
    It is the simplest and has no write conflicts. Most apps never need more.
  2. 2
    Ask where writes must happen
    If users in several regions need fast writes, or devices must write while offline, consider multi-leader.
  3. 3
    Ask what a conflict costs
    Losing a like is fine. Losing a payment is not. This decides whether LWW is acceptable.
  4. 4
    Prefer merge-friendly data
    Counters, sets and append-only logs merge safely. A single text field does not.
  5. 5
    Consider leaderless for always-on writes
    If the system must accept writes even when many nodes are down, use quorums and accept looser consistency.
  6. 6
    Plan failover and repair
    Single-leader needs fencing. Leaderless needs repair jobs. Both need monitoring and practice.
  7. 7
    Test with failures
    Cut the network between regions, kill nodes, write at the same time on both sides, and look at what you get.
💡A simple rule of thumb
If you can solve your problem with one leader and read replicas, do that. Move to multiple writers only when a real need (latency, offline use, availability) forces you to.
⚠️Do not trust timestamps blindly
Last-write-wins depends on clocks. Two machines can disagree by a little, so the "later" write may not be the one the user made last. Treat LWW as a convenience for data you can afford to lose.

08Key Terms to Know

TermMeaning in easy words
Leader / primaryThe node that accepts writes (in leader-based models)
Follower / replicaA node that copies another node's changes
Single-leaderOne node takes all writes; others copy it
Multi-leaderSeveral nodes take writes and copy each other
LeaderlessAny node takes writes; a quorum decides success
Write conflictTwo writes to the same data that did not see each other
Last-write-wins (LWW)Keep the value with the latest timestamp and drop the other
SiblingOne of several conflicting versions kept side by side
Read repairFixing an old replica when a read finds it is behind
Hinted handoffHolding a write for a down node and giving it back later
Anti-entropyA background job that compares and repairs replicas

09Pros, Cons and Trade-offs

✅ Pros
  • Single-leader: simple, one order of writes, no conflicts
  • Multi-leader: fast local writes, works across regions and offline
  • Leaderless: no leader to fail, writes keep working with some nodes down
  • You can pick the model that fits the data and the failures you expect
⚠️ Cons
  • Single-leader: one write path, and failover needs care
  • Multi-leader: conflicts, odd orderings and harder reasoning
  • Leaderless: weaker guarantees and repair jobs to run
  • More moving parts the more writers you allow

Trade-offs

ChoiceWe gainWe lose
Single-leaderSimplicity and a clear order of writesWrite scale and write speed far from the leader
Multi-leaderLocal writes in every region, offline writesYou must resolve conflicts
LeaderlessHigh availability for writesStrong consistency, and you need repair
LWW conflict ruleSimple, always gives one answerCan silently drop a write
Merge conflict ruleNothing is lostOnly some data types can be merged
Sync replicationNo loss of confirmed writesSlower, and a slow follower can block writes

10Common Problems and Mistakes

Common mistakes

  1. Choosing multi-leader too early. Teams take on conflict handling when one leader and read replicas would have been enough.
  2. Trusting LWW for important data. A lost update to a profile may be fine. A lost update to a balance is not.
  3. Failover without fencing. The old leader comes back and both accept writes. This is split brain.
  4. Assuming a quorum means strong consistency. Concurrent writes and sloppy quorums can still return old or conflicting data.
  5. Never running repair. In a leaderless store, replicas that missed writes stay behind until read repair or anti-entropy fixes them.
  6. Ignoring write order across leaders. An update can arrive at a leader before the create it belongs to.

Things to watch

🧠Split brain
Two nodes both think they are the leader. Use fencing and quorum-based elections.
⏰Clock skew
Timestamps from different machines do not match exactly, so LWW can pick the wrong winner.
🧩Sibling build-up
If nobody merges siblings, they pile up and slow down reads.
🌐Cross-region lag
Writes between regions take time, so conflicts are more likely than they look.

11Real-World Examples

🐘PostgreSQL and MySQL
Single-leader with read replicas is the default setup in most companies.
🍃MongoDB
A replica set has one primary. A new primary is elected if it stops responding.
🪐Cassandra
Leaderless: each row is stored on several nodes and read or written at a chosen consistency level.
📱Offline-first apps
Each device keeps its own copy and syncs later, which is multi-leader with a merge rule.
📝Shared documents
Editors in many places merge changes, using Operational Transformation or CRDTs.
📨Kafka
Each partition has a leader and follower replicas.
📝Note
Names, defaults and guarantees change between products and versions. Check the documentation of the system you use.
Mini case: a shop with two regions
👥EU shoppers
→↓write
👑EU leader
↔replicate
👑US leader
→↓write
👥US shoppers
Users Leaders Cross-region copy
Each region has a local leader, so shoppers write fast. Conflicts on the same order are rare, and the rule is merge for the cart, LWW for the profile photo.

12Related Topics to Read Next

Replication→

The basics: why we keep copies, and sync vs async.

Replication Lag→

What users see because copies are behind.

Quorum (R + W > N)→

The rule that leaderless systems use for reads and writes.

Split Brain Problem→

What goes wrong when two nodes both act as leader.

CRDTs→

Data types that merge safely after concurrent writes.

Consistency Models→

The promises each model can and cannot make.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔Question: who may accept a write?
  • ✔Single-leader: one writer, no conflicts, one write path. Start here.
  • ✔Multi-leader: a writer per region or device, fast local writes, conflicts to resolve.
  • ✔Leaderless: any node, quorum reads and writes, repair in the background.
  • ✔Conflict rules: avoid, LWW (can lose data), merge (CRDTs), or keep siblings.
  • ✔Repair: read repair, hinted handoff, anti-entropy (Merkle trees).
  • ✔Danger: split brain. Use fencing and majority elections.
  • ✔One line: “More writers means more speed and availability, and more disagreements to settle.”
← Previous
Connection Pooling
Next →
Replication Lag