Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Reliability and Failure
Lesson 17 of 24

Consistency under failure: split brain and fencing

Prevent two nodes from both believing they are the leader, and stop stale leaders from writing.

20 min read

Split brain

Automatic failover relies on deciding that the leader is dead. But in a network partition, the old leader may be alive and still accepting writes from clients on its side, while the other side promotes a new leader. Two leaders accept conflicting writes: the same seat sold twice, the same account debited twice. When the partition heals, one side's writes must be discarded or manually merged. Split brain is one of the most expensive failure modes because it corrupts data rather than just causing downtime.

Quorums

The standard defence is a majority quorum: a node may act as leader only while a majority of nodes agree. With 2f + 1 nodes, the cluster tolerates f failures and two majorities always overlap, so two leaders can never both hold a majority. That is why consensus clusters (etcd, ZooKeeper, Raft-based databases) use 3 or 5 nodes, and why 2 nodes is a poor choice: neither side of a split has a majority, so neither can safely continue. A 2-zone deployment needs a tie-breaker in a third zone.

Leases and fencing tokens

A leader typically holds a lease that expires unless renewed. But a process can pause for 30 seconds in garbage collection or a VM migration, wake up, and still believe its expired lease is valid. Fencing fixes this. Each time the lock service grants leadership it issues a monotonically increasing token (33, then 34). The leader sends its token with every write, and the storage layer rejects any write carrying a token lower than the highest it has seen. A paused old leader with token 33 cannot overwrite data written under 34.

Choosing behaviour during a partition

During a partition you must choose for each piece of data. There is no free option; you only choose which failure users see.

  • Consistency first: the minority side refuses writes, so some users see errors (seat inventory, ledgers, order books)
  • Availability first: both sides accept writes and reconcile later with merge rules or conflict resolution (carts, likes, file sync with conflict copies)
  • Write the choice down per data type; it is a product decision as much as a technical one

Key takeaways

  • Failover during a partition can create two leaders that accept conflicting writes
  • Majority quorums of 3 or 5 nodes prevent split brain; 2 nodes cannot
  • Fencing tokens let storage reject writes from leaders whose lease has expired
  • Choose consistency or availability per data type during partitions

Sign in to track lessons and earn badges.

Data integrity: checksums, idempotency and double entryBackups and restore drills

Coming up

Course: 0/24 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 7/10Design a File Sync ServiceProtect user files with chunk checksums, conflict handling during partitions and restorable versioned backups.Medium
  2. 8/10Design a Payment Ledger
Build a double-entry ledger with idempotent transfers, fenced writers and an RPO of zero.
MAJORHardPRO
All 10 challenges →