Course contentsShow
← System Design
Lesson 621 of 1,91917. Consensus AlgorithmsFree lesson

Leader Election: RequestVote RPC

How candidates request votes from other servers, including the vote-granting rules and majority requirement.

Leader Election: RequestVote RPC

What you'll learn: How candidates in Raft request votes from other servers to become the new leader, including the rules servers use to grant or deny votes.

When a follower times out and becomes a candidate, it must ask for permission to lead the cluster. It does this by sending a RequestVote RPC (Remote Procedure Call) to all other servers.

How RequestVote Works

Think of this like a political campaign: the candidate sends out a message saying "I want to be leader for term X, will you vote for me?" Each server receives this request and decides whether to grant its vote based on strict rules.

The candidate includes:

  • Its current term number (the election period)
  • Its own identity
  • Information about its log state (covered in future lessons)

Vote-Granting Rules

A server will grant its vote to a candidate only if:

  1. The candidate's term is at least as current as the server's own term
  2. The server hasn't already voted for a different candidate in this term
  3. The candidate's log is at least as up-to-date as the server's log (details later)

Each server can vote for at most one candidate per term — no double-voting allowed.

The Majority Requirement

To win the election, a candidate must receive votes from a strict majority of servers in the cluster (more than half). In a 5-node cluster, that means at least 3 votes. This majority rule ensures only one leader can be elected per term, preventing split-brain scenarios.

If no candidate achieves majority (a split vote), servers time out and start a new election with an incremented term.

Key Takeaway: RequestVote RPC is Raft's voting mechanism where candidates ask for votes, servers grant votes once per term based on freshness rules, and a strict majority is required to win leadership.