Split-Brain
criticalSummary
A failover mechanism promotes a new leader without confirming the old one has stopped, so two nodes simultaneously believe they hold the primary role and both accept writes. The two histories diverge, and when the partition that triggered the failover heals, one set of committed transactions must be discarded.
Description
Split-brain is the specific failure that happens when a network_partition triggers a failover, and the failover has no way to guarantee the old primary has actually stopped accepting writes before the new one starts. It is not partition tolerance gone wrong in the abstract; it is a concrete gap in the promotion procedure.
In a PostgreSQL primary-standby setup without fencing, the primary and standby sit behind a virtual IP, each with its own connectivity to application servers. A partition isolates the primary from the standby but not from either one's own application servers. Patroni or repmgr on the standby detects the primary is unreachable and, after the failover timeout (typically 30 seconds), promotes the standby. Both nodes now accept writes: the original primary from its own application servers, which never learned it should stop, and the new primary from its own. When the network heals, the two write-ahead logs have diverged with conflicting committed transactions, and one side's must be discarded.
In Redis Sentinel with three sentinels, a partition isolating the primary from two of the three sentinels triggers promotion of a replica. If the original primary keeps connectivity to some application instances (its own availability zone, say), those instances keep writing to it. When the partition heals, the original primary holds writes the new primary does not, and because Redis replication is one-directional, those writes are simply lost during forced resynchronization rather than merged.
Fencing is the defense, and there are two different mechanisms sold under that name. STONITH-style fencing (Shoot The Other Node In The Head) acts on the old primary from the outside: cut its network access, power it off via IPMI, revoke its cloud network interface. It works, but it requires infrastructure access and takes time to execute. Fencing-token-style fencing acts at the storage layer instead: every write carries a monotonically increasing token from the current leadership term, and the storage layer rejects any write bearing a token older than the highest it has already accepted. A demoted primary that never got the message keeps sending writes with its old token, and those are rejected on arrival rather than accepted and later discovered to conflict; no external action against the old primary is required. The leader_election pattern covers fencing tokens as the general-purpose mechanism; STONITH is the infrastructure-level equivalent used when the leadership role itself controls a physical or network resource rather than a storage write path.
Consensus-based election prevents split-brain by construction, but the precise claim is narrower than "impossible to have two leaders": Raft guarantees at most one leader per term, because election requires a majority vote and any two majorities of the same cluster must overlap by at least one node, so two disjoint groups cannot each elect a leader in the same term. A new term with a new leader can still follow an old one; what cannot happen is two simultaneously valid leaders in one term, which is exactly the split-brain condition.
The data damage from split-brain is permanent once it occurs: committed transactions on the demoted node are lost. Depending on what those transactions were (financial writes, order state changes, account modifications), the damage may require manual reconciliation or may be unrecoverable.
Characteristics
Triggers
- ·Network partition between primary and replica with no fencing mechanism
- ·Failover automation that promotes a replica before confirming the primary has stopped
- ·A partition pattern where primary and replica each retain application connectivity in their own segment
- ·Leader election on a Redis TTL-based lease where the leader experiences a GC pause longer than the lease TTL
- ·Kubernetes pod rescheduling that starts a new primary instance before the old one has terminated
Detection Signals
Mitigation Strategies
Before a new primary starts accepting writes, the failover manager fences the old one: cutting its network access, powering it off via IPMI, or revoking its cloud network interface, and only then releasing the new primary to accept writes. Patroni with etcd implements this via a leader key; cloud environments can use security-group changes or instance-stop APIs. The cost is the time the fencing action itself takes, during which the system is unavailable rather than split.
Configure synchronous_standby_names = 'ANY 1 (replica1, replica2)'. The primary will not confirm a write until at least one replica acknowledges, so a primary that loses all replica connectivity stalls on new writes rather than completing ones no replica can confirm. This bounds what the original primary can do during a partition; it does not by itself fence a promoted replica, so pair it with an explicit fencing mechanism. Adds one round trip of write latency.
Replace ad-hoc failover scripts with a Raft-based consensus system (etcd, Consul, Patroni with a DCS). Electing a leader requires a majority, and a node that cannot reach one cannot be elected, so two disjoint groups cannot each produce a valid leader in the same term. This is the mechanism, not just a policy: it holds as long as the storage layer's writes are actually gated by the elected leader's term.
Require a human operator to confirm the primary is unreachable before promoting a replica. Eliminates automated split-brain at the cost of a longer mean time to recovery during genuine primary failures.
Recovery Steps
- 1.Immediately isolate both nodes from all application traffic to stop further divergent writes
- 2.Determine which node has the most recent data (compare pg_current_wal_lsn or the transaction timestamp range on each)
- 3.Demote the node with less data: stop PostgreSQL and remove its primary designation
- 4.Identify every transaction on the demoted node that does not exist on the winning node
- 5.Assess and manually reconcile lost transactions: contact business teams for financial or inventory discrepancies
- 6.Resync the demoted node as a replica of the winning node; validate replication health before re-enabling application traffic
Estimated recovery time: 1 to 6 hours for technical recovery. Business data reconciliation may take days if the lost transactions involve financial, inventory, or user-visible state. Damage scope is proportional to the split-brain window's duration and the write rate during it.
Affected Systems
Patterns
Technologies
Basis
Extensively documented failure mode in distributed databases; the majority-quorum argument for at-most-one-leader-per-term is a standard Raft/Paxos consensus result, and the STONITH-versus-fencing-token distinction is established practice (Kleppmann's fencing token treatment; Patroni and Pacemaker documentation).
Run This Failure
Blast radius analysis for this failure mode within each scenario that carries it.
Related Architecture Knowledge
Inbound: affects this entity
Leader election ensures only one node is authoritative at any time, preventing split-brain by using a consensus protocol that requires a quorum of nodes to agree before a leader is promoted: making it impossible for two nodes to simultaneously believe they are the leader.
Tradeoffs
- ·Quorum-based election requires an odd number of nodes: a 2-node cluster cannot elect a leader after any partition
- ·Leader election adds a failover latency window (typically 5-30 seconds) during which the system is unavailable for writes
- ·The elected leader is a single point of throughput: all writes must go through the leader in a strong-consistency system
The outbox pattern eliminates split-brain between a database write and a message broker publish by writing both the domain record and the outbox event in a single ACID transaction, ensuring events are published if and only if the database write committed.
Tradeoffs
- ·Adds ~1ms write overhead per transaction for the outbox INSERT
- ·Relay is a single point of failure: relay high availability requires careful deployment
- ·At-least-once delivery means consumers must handle duplicate events: idempotency key required
Two-phase commit's coordinator is a single point of failure. If the coordinator crashes after sending the prepare phase but before completing the commit phase, participants are left in an uncertain state: some may have committed and some not, creating a split-brain condition that requires manual operator intervention.
Tradeoffs
- ·2PC is blocking: if any participant cannot respond, the entire transaction is blocked indefinitely
- ·Locks held during 2PC are held across the network: lock duration includes network latency
- ·The coordinator is a scalability bottleneck: all distributed writes serialize through it
Used In Architecture Scenarios
Financial Ledger
A strict consistency financial architecture for double-entry accounting, payment processing, and audit trail management where every debit must have a corresponding credit, every state transition must be ordered and durable, and the complete history must be reconstructable without gaps. Event sourcing provides an append-only audit log; the outbox pattern guarantees at-least-once downstream event delivery without distributed two-phase commit (idempotent consumers deduplicate on event ID for effectively-once processing); PostgreSQL provides ACID guarantees for ledger entry atomicity.
Realtime Collaboration
An online multiplayer game backend built around authoritative server game state synchronization. Game rooms run as distributed state machines where the server is the single source of truth for game state: client predictions are reconciled against the server state at every tick. WebSocket connections provide low-latency bidirectional communication for state deltas. Redis stores active game room state (in-flight, with sub-millisecond access), session affinity tokens (routing players to the same server instance as their game room), and matchmaking queues. PostgreSQL is the durable store for player profiles, persistent inventory, leaderboards, and achievement records. Kafka carries post-game event streams for analytics, anti-cheat processing, and achievement evaluation. NATS provides low-latency pub/sub for intra-cluster game state broadcasting when multiple game server instances must coordinate on shared state. Event sourcing records every game action as an immutable event for replay, dispute resolution, and anti-cheat audit.