Server States: Leader, Follower, Candidate
You'll learn: The three states a Raft server can be in and how transitions between them drive consensus.
The Three States
In Raft's design for understandability, every server exists in exactly one of three states at any moment:
Follower — The passive state. Followers don't initiate actions; they simply respond to requests from leaders and candidates. When a cluster starts, all servers begin as followers. They wait to hear from a leader.
Candidate — The campaigning state. When a follower stops hearing from a leader (election timeout expires), it transitions to candidate and starts an election, requesting votes from other servers to become the new leader.
Leader — The active state. Only one leader exists per term. The leader handles all client requests, replicates log entries to followers, and sends regular heartbeats to prevent followers from starting new elections.
State Transitions
Think of it like a classroom: normally everyone's a follower (student) listening to the leader (teacher). If the teacher disappears and doesn't return after a timeout, one student becomes a candidate and campaigns: "Should I be the new teacher?" If they get majority votes, they become the leader. If they lose or another teacher appears, they return to being a follower.
The transitions flow naturally:
- Follower → Candidate (election timeout, no leader heard from)
- Candidate → Leader (receives majority votes)
- Candidate → Follower (discovers current leader or loses election)
- Leader → Follower (discovers server with higher term number)
This state-machine approach keeps Raft simple: each state has clear responsibilities, and transitions have explicit triggers.
Key Takeaway: Raft servers cycle through three states—Follower (passive), Candidate (campaigning), and Leader (active)—with well-defined transitions that drive leader election and maintain exactly one leader per term.