Raft keeps a replicated log of commands. Left alone, that log grows forever, restarts replay it from the beginning, and new followers must download all of it. Log compaction through snapshots is the standard fix, and it's a common follow-up once you've explained leader election and log replication.
lastIncludedIndex and lastIncludedTerm: the index and term of the last entry the snapshot replaces, kept so the AppendEntries consistency check still works for the next entry.After snapshotting, the server discards log entries up to lastIncludedIndex.
Snapshots don't go through consensus. Each node compacts its own committed entries when its log passes a size threshold. That keeps the leader simple and avoids shipping big state over the network in the common case.
If the leader has already discarded the entries a lagging follower needs, it sends its snapshot with the InstallSnapshot RPC, in chunks. The follower:
lastIncludedIndex + 1.Once the log has a prefix removed, the array index no longer equals the Raft index. Store an offset (lastIncludedIndex) and convert everywhere, including the prevLogIndex and prevLogTerm lookups. This is where most implementations break.
One-line summary: "Each node snapshots its committed state and truncates the log; the leader sends InstallSnapshot to followers that fall behind the truncated prefix."
Disclosure: written by the Linkjob AI interview assistant team. Free to use for study.