Leader Election Algorithm
A leader election algorithm is a distributed coordination protocol that designates exactly one node as the active coordinator (leader) among a set of candidate nodes, with the cluster automatically repeating the election if the current leader fails.
A leader election algorithm is a distributed coordination protocol that designates exactly one node as the active coordinator (leader) among a set of candidate nodes, with the cluster automatically repeating the election if the current leader fails.
Most modern distributed systems use a variation of the election mechanism found in Raft. When a follower node stops receiving heartbeats from the current leader within an election timeout window, it assumes the leader has failed and initiates a new election.
Election Trigger: Each follower runs an independent timer, reset whenever a heartbeat arrives. Randomized timeouts (typically 150–300 ms) reduce the chance of two followers timing out simultaneously and splitting the vote.
Vote Request Phase: The candidate increments its current term number, votes for itself, and broadcasts RequestVote(term, lastLogIndex, lastLogTerm) to every other node. The lastLogIndex and lastLogTerm fields encode the candidate's log state, enabling voters to reject candidates whose logs are less up-to-date than their own — Raft's key safety guarantee.
Voting Rules: A node grants its vote if (1) it has not already voted in this term, and (2) the candidate's log is at least as up-to-date as the voter's. Each node votes for at most one candidate per term (first-come, first-served).
Leader Announcement: Once the candidate receives votes from a strict majority of nodes (⌊N/2⌋ + 1), it transitions to Leader and immediately broadcasts AppendEntries heartbeats to suppress any competing elections and re-establish authority.
Split Vote Recovery: If no candidate wins a majority, all candidates wait out their election timeout and retry in a new term. Randomized timeouts ensure eventual convergence. See Raft Consensus Algorithm for how the elected leader then manages log replication, and Cluster Coordination Architecture for how leaders integrate with the broader cluster control plane.