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

AppendEntries RPC: Replication Mechanism

How the leader replicates log entries to followers using AppendEntries, including heartbeats to maintain authority.

AppendEntries RPC: Replication Mechanism

You'll learn how the Raft leader uses AppendEntries RPC to replicate log entries to followers and maintain its authority.

The Core Idea

In Raft, once a leader is elected, it must do two things: replicate new commands to followers and prove it's still alive. Both are accomplished through the AppendEntries RPC—the fundamental replication mechanism that the leader sends periodically to all followers.

Think of the leader as a manager broadcasting updates to their team. Each message either contains new work assignments (log entries) or simply says "I'm still here, still in charge" (a heartbeat).

How AppendEntries Works

The leader sends AppendEntries RPCs to all followers at regular intervals. Each message includes:

  • Leader's term: So followers can verify authority
  • Log entries: New commands to replicate (if any)
  • Previous log information: To ensure consistency with the follower's log
  • Commit index: Tells followers which entries are safe to apply

When a follower receives AppendEntries, it performs consistency checks. If the follower's log matches the leader's expectations (based on previous log information), it appends the new entries and responds with success.

Heartbeats: Empty AppendEntries

When there are no new entries to replicate, the leader still sends AppendEntries with an empty entry list—these are heartbeats. They serve two purposes:

  1. Prevent new elections: Followers reset their election timeouts when receiving valid heartbeats
  2. Maintain leadership: Proves the leader is operational

Without regular heartbeats, followers would assume the leader crashed and trigger a new election.

Key Takeaway: AppendEntries RPC is Raft's workhorse—the leader uses it both to replicate log entries to followers and to send heartbeats that suppress elections and maintain authority.