Try
↑ ↓ move↵ openesc close

Interview prep / Raft and consensus

Mid · Raft and consensus · System design interview question

A new leader has ten log entries. A follower has seven, and its entries 6 and 7 are from an older term and differ from the leader's. How does the leader bring the follower into line, and why is it safe to delete the follower's entries?

Sketch your own answer first, then compare it with the one below.

A strong answer

The leader starts with a guess that the follower is current, so it sends the entry after its own last one and names the entry before as the anchor, with that entry's index and term. The follower has no entry at index 10, so it rejects. The leader lowers its guess for that follower by one and tries again, through anchors 9, 8, 7 and 6, each rejected because the follower either has no entry there or holds one with a different term. At anchor 5 the index and term agree, so the follower accepts.

On accepting, the follower deletes everything after index 5 and appends the leader's entries 6 to 10. That is five rejections and a success.

The deleted entries are safe to drop because they were never committed. A committed entry is on a majority, and the election restriction would have stopped a leader without it from winning, so the leader would hold it. Whatever the follower has that the leader lacks must therefore be uncommitted. For long gaps, the follower can return the conflicting term and the first index of that term, which lets the leader skip back a whole term at a time.

Sources

Learn it by running it

The raft consensus lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms