Knowledge Guide
HomeSystem DesignScalable Systems (Advanced Topics)

hard Split-Brain, Fencing & Safe Failover

Why promoting a second primary can silently corrupt your data

A failover controller promotes a replica when it decides the primary is dead. But over a network it cannot distinguish “primary crashed” from “primary is alive but I can’t reach it” — that is the partition. If the old primary is actually alive and still taking writes while a replica is promoted, you now have two nodes that both believe they are primary. Both accept writes, their histories diverge, and there is no correct automatic way to merge them. That is split-brain.

A second, quieter failure rides along with it. With asynchronous replication the primary acks a write to the client before the replica has it. Promote that lagging replica and every acked-but-unshipped write vanishes — the client was told “committed,” yet the new primary never saw it. Durability is violated even without two primaries.

Timeline: primary P acks write W1 but it is not yet replicated to R1; a partition forms; R1 is promoted without W1; both P and R1 then accept writes and diverge
Timeline: primary P acks write W1 but it is not yet replicated to R1; a partition forms; R1 is promoted without W1; both P and R1 then accept writes and diverge

A traced failover timeline

Three nodes: primary P, replicas R1, R2, asynchronous replication, one key x.

tEventState / consequence
t0P primary, x=1 everywherehealthy
t1Client writes x=5 to P; P acks the clientW1 acked, but not yet shipped to R1/R2
t2Network partition isolates P from the replicas and the controllerP looks “dead” from the other side
t3Controller promotes R1 to primaryR1 still has x=1 — W1 (x=5) is lost
t4A client still reaching P writes x=7 to P; another client writes x=9 to R1two primaries, histories diverge
t5Partition healsx=7 vs x=9 conflict, and W1=5 was acked yet is gone

The three fixes (they solve different halves of the problem)

1. Quorum-based promotion — prevents two winners

Require a majority of nodes to agree before anyone is promoted. With 3 nodes the majority is 2. When the partition splits the cluster into {P} and {R1, R2}, only the {R1, R2} side has 2 votes ≥ majority, so only that side can elect a leader. The lone P cannot assemble a majority, so a quorum-respecting P steps down and stops accepting writes. Because two disjoint groups can never both hold a majority of the same cluster, you can never elect two leaders. This is exactly how Raft and Paxos leader election avoid split-brain.

2. Fencing — stops a deposed primary that didn’t get the memo

Quorum stops a well-behaved old primary. But a node paused in a long GC or a network stall may wake up believing it is still primary and try to write. Fencing blocks that write:

3. Synchronous replication — prevents the lost acked write

Have the primary wait for a replica to durably ack before it acks the client. Now a promoted replica already holds every acked write, so W1 can never be lost. The cost: every write pays the round-trip to the replica, and if the replica is down the primary cannot ack at all — you have traded availability for durability. Semi-synchronous (wait for any one of several replicas) is the common middle ground.

Pitfalls

The judgment layer

Synchronous vs asynchronous replication. Sync gives zero data loss on failover (RPO=0) but raises write latency and reduces availability when a replica is slow or down — the right choice for money and source-of-truth state. Async keeps writes fast and the primary available even when replicas lag, at the price of a bounded window of writes that can be lost on promotion — the right choice when a few lost seconds of the newest data is survivable (analytics, feeds). Semi-sync (ack after ≥1 replica) buys most of the durability for a fraction of the latency hit.

Fencing token vs STONITH. A fencing token is clean and hardware-free but requires the shared resource (storage, DB) to be token-aware and reject stale tokens — cooperative fencing. STONITH needs no cooperation from the resource (it removes the node entirely) but requires a reliable power/management channel and a tiebreaker to avoid mutual kills. Use a token when the resource can enforce it; fall back to STONITH when it cannot.

Takeaways


Synthesized from Kleppmann, Designing Data-Intensive Applications (Ch. 5, 8, 9) and “How to do distributed locking” (fencing tokens), the Raft paper (leader election / quorum), and Linux-HA / Pacemaker STONITH practice. Re-authored/Deepened for this guide.

🤖 Don't fully get this? Learn it with Claude

Stuck on Split-Brain, Fencing & Safe Failover? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Split-Brain, Fencing & Safe Failover** (System Design) and want to truly understand it. Explain Split-Brain, Fencing & Safe Failover from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Split-Brain, Fencing & Safe Failover** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Split-Brain, Fencing & Safe Failover** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Split-Brain, Fencing & Safe Failover** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes