Log Structure and Entries
What you'll learn: How Raft organizes commands into a replicated log using entries that track term numbers and index positions.
The Core Idea
In Raft, every server maintains a log — an ordered sequence of entries. Each entry represents a command from a client that needs to be executed. Think of the log like a numbered notebook where each page records one instruction and the era (term) when it was written.
The log is the foundation of replication: all servers work to maintain identical copies of this log, ensuring they execute the same commands in the same order.
Anatomy of a Log Entry
Each log entry contains three essential pieces:
- Command: The actual operation to execute (e.g., "set x = 5")
- Term Number: The term during which the leader received this command — acts like a timestamp showing which leadership period created this entry
- Index Position: The entry's position in the log (1, 2, 3, ...) — entries are never inserted in the middle; they're always appended
Why This Structure Matters
The index ensures total ordering: entry 5 always comes before entry 6. The term number helps resolve conflicts when logs diverge. If two entries at the same index have different terms, Raft knows which leader's version is authoritative (higher terms win).
The log grows as the leader receives commands and shrinks only through controlled snapshots. Once an entry is committed (replicated on a majority of servers), it becomes durable and safe to execute.
Key Takeaway: Raft's replicated log is an append-only, ordered sequence of entries, each containing a command, term number, and index position — forming the single source of truth for state machine replication.