Thursday, December 3, 2026 | London 10°C · Drizzle
DailyGlimpse

AI

Demystifying ETCD Leader Election: A Deep Dive into the Raft Algorithm

Technical Cloud Knowledge 2 min read

In distributed systems, consensus algorithms ensure that multiple nodes agree on a single source of truth. ETCD, the key-value store that underpins Kubernetes, relies on the Raft algorithm to elect a leader and maintain cluster consistency. But how exactly does a leader get elected? Let's break it down.

Raft States: Leader, Follower, and Candidate

Every node in an ETCD cluster starts as a Follower. Followers expect periodic heartbeats from the current Leader. If a follower doesn't receive a heartbeat within a certain time (the Election Timeout), it transitions to a Candidate state and initiates a new election.

The Election Process

  1. A candidate increments its term number and votes for itself.
  2. It sends RequestVote RPCs to all other nodes.
  3. Other nodes vote for the candidate if they haven't already voted in that term and if the candidate's log is at least as up-to-date as theirs.
  4. If a candidate receives votes from a majority (quorum) of the cluster, it becomes the new Leader.

Heartbeats and Timeouts

  • The new Leader begins sending heartbeats (AppendEntries RPCs) to all followers to assert its authority.
  • Heartbeats reset the election timers on followers, preventing unnecessary elections.
  • The election timeout is randomized (typically 150–300 ms) to reduce the chance of multiple nodes becoming candidates simultaneously.

Quorum and Failover

ETCD requires a majority (>50%) of nodes to agree on a leader. So in a 3-node cluster, at least 2 nodes must vote. If the leader fails, a new election automatically triggers after the timeout, ensuring high availability without manual intervention.

Why This Matters for Kubernetes

Kubernetes relies on ETCD to store all cluster state. If ETCD has no leader, the entire cluster becomes unavailable. The Raft algorithm guarantees that even if some nodes fail, a leader can still be elected as long as a quorum remains.

This internal mechanism is what allows Kubernetes multi-master setups to remain resilient and consistent under failure scenarios.

React