SPLIT BRAIN

Two leaders, one disaster

L215 MINDISTRIBUTED SYSTEMS
PREDICT

A 5-node cluster partitions into {N1,N2} (N1 leads) and {N3,N4,N5}. Clients keep writing to N1. With majority quorum enforced, what happens to those writes?

A cluster has one leader so that writes have one order. A partition cuts the leader off from most of its followers. The followers time out and elect a new leader; the old one, hearing nothing, keeps going. Now two nodes accept writes for the same data under different epochs. Both acknowledge. When the network heals, one history has to lose. The guard is that a leader must keep proving it is heard by a majority, and that storage must refuse any leader whose epoch is older than the newest it has seen.

▶ SIMULATION
LEFT {N1,N2}
N1: LEADER @1
N2: follower @1
log: (empty)
NETWORK / STORAGE
network: connected
cluster epoch: 1
storage fence: off
nodes accepting writes: 1 (N1)
acked writes lost: 0
RIGHT {N3,N4,N5}
N3: follower @1
N4: follower @1
N5: follower @1
log: (empty)
writes—
eventN1 leads at epoch 1. Five nodes, one network.
✓ at most one node accepts writes at any time✓ no acknowledged write is lost
SCHEDULE
01[SETUP]SETUP: N1 never checks quorum; storage accepts any epoch
02[CLIENT]client → N1: write
03[NET]NET: partition {N1,N2} | {N3,N4,N5}
04[N1]N1: heartbeat to all followers, count who answers
05[N3]N3: election timer fires — heard a leader? stay follower : run election
06[CLIENT]client → N1: write
07[CLIENT]client → N3: write (N3 forwards to the leader it knows)
08[NET]NET: partition heals — lower epoch side reconciles
09[SYSTEM]verdict
Start of two leaders scenario. 9 steps.
// Leader, on client write:
append(write);          // no quorum check
reply(ACK);             // client believes it is durable

// Follower, on election timeout:
becomeLeader();         // nobody told the old leader

Watch the invariant strip. In TWO LEADERS it turns red the moment N3 wins its election while N1 is still accepting, and stays red through heal when w2 is discarded. In both fixes the same partition, the same election and the same client writes happen, and the strip stays green: the count of nodes accepting writes never passes 1. FIX: QUORUM models the check-quorum rule: N1 refuses writes it cannot replicate to a majority and steps down on a short heartbeat.

FIX: FENCING is green partly because of the schedule. Fencing protects storage from a stale leader once the new epoch is set. It does nothing for a write N1 acknowledges in the window between the partition and N3’s fence step: N1 has no quorum commit here, so that write is acked on 2 of 5 nodes and discarded at heal. That is why real systems combine the two layers: quorum commit so nothing is acknowledged without a majority, and fencing so a deposed leader cannot write.

INJECT A FAULT NOT YET

This cluster never checks quorum and has no fencing, but with a healthy network nothing goes wrong. Inject the partition at the step where two nodes end up acknowledging writes and a client loses a write it was told succeeded.

GOAL: two nodes accept writes at once, or an acknowledged write is lost at heal

FIX IT NOT YET

Storage receives every write tagged with the epoch of the leader that sent it. Implement acceptWrite so a leader from an older epoch than the newest one storage has seen is rejected, while a legitimate leader keeps writing. The grader replays a partition, a stale leader, and a re-election.

Mental model:

Leadership is not a fact a node knows about itself; it is a claim the majority has to keep renewing. A leader that cannot reach a majority must stop, and because it might not stop (paused, stalled clock, buggy), every write it sends carries its epoch so that storage can refuse the stale one. Quorum limits who can lead; fencing limits what a leader that should have stopped can do.

IN PRODUCTION

Database failover (MySQL with Orchestrator, Postgres with Patroni), ZooKeeper or etcd lock services, Kafka controller elections, any primary/replica pair with an automatic promotion script. Symptom: both sides served writes during an incident and the post-mortem has a section titled “data reconciliation”.

IN INTERVIEWS

“What is split brain and how do you prevent it?” Name the two layers: majority quorum so at most one side can elect and commit, and fencing tokens (epochs) so a leader that failed to notice it lost cannot write. Mention the GC-pause case to show why quorum alone is not enough, and say honestly which acknowledged writes are lost at heal.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: FAILURE MODELS & TIMEOUTS →