Raft's Log Replication Protocol

Learn how the log replication works in Raft.

A log comprises one or multiple log entries, and each entry holds an executable application-specific command. The basic responsibility of Raft is to maintain a consistent sequential log across all servers. Let’s see how Raft implements this in its algorithm.

Log replication

After a leader is chosen in an election, it handles client requests. These requests contain instructions to be executed by the state machines. The leader adds the instruction to its log as a new entry and sends AppendEntries RPCs to all other servers in parallel to replicate the entry. Once the entry has been replicated safely (after a majority of the followers have successfully replicated it), the leader applies it to its own state machine and provides the result of the execution to the client.

Suppose followers malfunction or operate slowly, or network packets are lost. In that case, the leader will continue to retry AppendEntries RPCs until all followers store all log entries, even after it has already responded to the client.

Press + to interact
A client sends a request (containing the state machine command) to the leader
1 / 5
A client sends a request (containing the state machine command) to the leader

Every record in the log contains an instruction for the state machine and the term number corresponding to when the leader received this instruction. The term numbers recorded in the log are utilized to identify disparities among logs, which we’ll discuss later in this lesson. Each entry in the log is assigned a unique integer index indicating its position within the log.

A single log entry
A single log entry

The following illustration shows a sample log organization in a Raft ...

Access this course and 1400+ top-rated courses and projects.