Raft RPCs: RequestVote and AppendEntries
What you'll learn: You'll understand the two core remote procedure calls that power Raft's leader election and log replication mechanisms.
The Two Pillars of Raft Communication
Raft coordinates distributed consensus through just two primary RPCs (Remote Procedure Calls). Think of them as the only two "verbs" servers use to talk to each other in the Raft protocol—one for choosing leaders, one for maintaining agreement.
RequestVote RPC
When a Candidate wants to become a Leader, it sends RequestVote RPCs to all other servers asking for their vote. This RPC contains:
- The candidate's current term (logical clock)
- Information about the candidate's log state
Receivers compare the candidate's term and log completeness against their own state. They grant their vote only if:
- They haven't voted for anyone else in this term
- The candidate's log is at least as up-to-date as theirs
This ensures only servers with complete logs can become leaders—preventing data loss.
AppendEntries RPC
Once elected, the Leader uses AppendEntries RPCs for two purposes:
- Heartbeats: Empty messages sent regularly to maintain authority and prevent new elections
- Log replication: Carrying new log entries to replicate across Followers
The RPC includes the leader's term, log entries (if any), and information about previously committed entries. Followers use this to stay synchronized with the leader's replicated state machine.
Think of RequestVote as "Should I be in charge?" and AppendEntries as "Here's what we're doing" or just "I'm still in charge."
Key Takeaway: Raft uses only two RPCs—RequestVote for leader election when servers compete for leadership, and AppendEntries for both heartbeat maintenance and log replication once a leader is established.