Two parts of a system both think they are in charge, and both accept writes.
Split brain happens when a system that should have one leader ends up with two, and both accept writes. The two "brains" then make different decisions and the data grows apart.
Many systems use a leader (also called primary or master) to decide the order of writes. Having one leader keeps things simple: everyone follows one source of truth.
The followers watch the leader with heartbeats. If the heartbeats stop, they assume the leader died and elect a new one. The trouble is that "the heartbeats stopped" does not mean "the leader died". Maybe the network is cut. Maybe the leader was frozen by a long garbage-collection pause. In both cases the old leader is still alive, and when it wakes up it still believes it is the leader.
| Cause | What happens | Who is surprised |
|---|---|---|
| Network partition | Leader is cut off from the followers, who elect a new one | The old leader, still serving its own clients |
| Long pause (GC, swap, VM freeze) | Leader stops for seconds, then continues as if nothing happened | The old leader, which wakes up still sure it leads |
| Wrong failure detector | A timeout is too short, so a slow leader is declared dead | Everyone, as the cluster flaps between leaders |
| Manual failover mistake | An operator promotes a replica without stopping the old primary | The team, a day later |
| Two nodes only | Each node can not tell if the other is dead or cut off | Both nodes, which both take over |
| Defence | How it works | Limit |
|---|---|---|
| Quorum writes | A write counts only if a majority acknowledge it | The minority side can not write, so it is unavailable |
| Terms / epochs | A new leader gets a bigger number. Nodes ignore messages from smaller numbers (Raft, Paxos) | Needs a consensus system to hand out the numbers |
| Fencing token | A lock or lease returns an increasing number. The storage refuses lower numbers | The storage must check tokens |
| Lease with expiry | A leader may act only until its lease ends, and must renew it | Clocks must not drift much, and a pause can still outlive the lease |
| STONITH (shoot the other node in the head) | Power off or isolate the old node before promoting a new one | Needs extra hardware or cloud API access |
| A witness / tie-breaker | A third small node that breaks 1-vs-1 ties | One more thing to place and run |
| Term | Meaning in easy words |
|---|---|
| Split brain | Two nodes (or groups) both act as the leader at the same time |
| Leader / primary | The node that decides the order of writes |
| Failover | Moving the leader role to another node when the leader seems to fail |
| Term / epoch | A number that increases with each new leader |
| Fencing token | An increasing number given with a lock, so storage can reject writes from an old holder |
| Lease | A permission that expires after a set time unless it is renewed |
| Quorum | A majority of nodes, needed to take a decision |
| STONITH | 'Shoot the other node in the head': forcing the old node to power off |
| Witness / tie-breaker | An extra node used only to settle votes |
| Stale leader (zombie) | An old leader that does not know it has been replaced |
| Failure detector | The part that decides, from heartbeats, if a node is down |
| Choice | We gain | We lose |
|---|---|---|
| Quorum required to write | No two leaders can both commit | No writes on the minority side |
| No quorum (any node may lead) | Always available | Split brain and conflicting data |
| Fast failure detection | Short downtime | More false alarms and needless failovers |
| Slow failure detection | Fewer false failovers | Longer outages when a leader really fails |
| Fencing tokens | Old leaders can not corrupt data | Storage must be able to check them |
| STONITH | Certain that the old node is off | Needs special hardware or access, and a bug can kill the wrong node |