Raft Server States: Follower, Candidate, Leader
What You'll Learn
You'll understand the three states every Raft server can occupy and how servers transition between them during normal operation and leader elections.
The Three States
In Raft, every server is always in exactly one of three states:
Follower
The passive state where most servers spend most of their time. Followers respond to requests from leaders and candidates but don't initiate actions themselves. Think of them as students in a classroom—they listen and respond when called upon, but don't lead the discussion.
Candidate
The transitional state a server enters when it believes the leader has failed. A candidate requests votes from other servers, attempting to become the new leader. This is like a student raising their hand to volunteer as group leader when the teacher is absent.
Leader
The active state where one server handles all client requests and manages replication to followers. Only one leader exists per term. The leader is like the teacher directing the class—everyone else follows their guidance.
State Transitions
- Follower → Candidate: When a follower's election timeout expires without hearing from the leader, it starts an election
- Candidate → Leader: When a candidate receives votes from a majority of servers (quorum)
- Candidate → Follower: When a candidate discovers a leader with an equal or higher term
- Leader → Follower: When the leader discovers another server with a higher term number
- Any state → Follower: When a server receives a message with a higher term number
Each transition is triggered by specific conditions related to timeouts, vote results, or discovering servers with newer information.
Key Takeaway: Raft servers cycle through three states—Follower (passive), Candidate (election mode), and Leader (active)—with transitions driven by timeouts, election results, and term numbers ensuring eventual convergence on a single leader.