Many distributed algorithms need a leader. Election algorithms pick one when the current leader dies. Three classic approaches, each with tradeoffs.

Bully Algorithmhighest ID winsRing Algorithmtoken around ringRaft Electionrandomized timeoutsO(N²) msgsmany probesO(N) msgsone passO(N) msgs avgexpected 1 roundSplit brain riskif partitionedDeterministicif ring intactMajority quorumno split brain
Three election algorithms with message cost + failure semantics
Advertisement

Bully algorithm

Node with highest ID wins. Any node detects leader failure → sends ELECTION to higher IDs. Anyone alive with higher ID responds + starts own election.

Bully algorithm

Node with highest ID wins. Any node detects leader failure → sends ELECTION to higher IDs. Anyone alive with higher ID responds + starts own election.

Advertisement

Ring algorithm

Nodes arranged in logical ring. Election token passed around. Each node adds its ID. Highest ID at token completion wins.

Raft election

Randomized timeouts (150-300ms). First node to time out becomes candidate + requests votes. Majority wins. Randomization prevents most contested elections.

Split brain risk

Bully + Ring can elect two leaders during network partition. Raft's majority quorum prevents it — one partition has majority, other doesn't.

Practical choice

Raft dominates modern systems. Bully + Ring appear in older systems (Zookeeper, some HA clusters) but Raft's understandability wins.

Bully → O(N²) + split brain. Ring → O(N) + single point of failure. Raft → majority quorum + practical.