Try
↑ ↓ move↵ openesc close

Interview prep / Raft and consensus

Senior · Raft and consensus · System design interview question

A five node Raft cluster is split so the leader is on a side with one other node. Describe what each side does, what clients see, and what happens when the partition heals.

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

A strong answer

The old leader keeps accepting client writes and appends them to its log, because nothing tells it to stop. But it can only replicate them to one follower, which is two of five. The commit index never moves, so those clients wait for acknowledgements that never come, or time out. Reads served by that leader are stale from now on unless it checks a majority before serving them.

The three node side stops hearing heartbeats, times out, and elects a leader in a higher term. That leader commits new entries, so this side is the real cluster. Clients that reach it make progress.

On heal, the old leader receives a message with the higher term and steps down. The new leader's heartbeat fails the consistency check at the point where the logs diverge, steps back, and the stale entries are deleted and replaced. The writes the minority leader accepted are gone, which is correct because they were never acknowledged as committed. Two things follow for clients. A write is only durable once acknowledged, and a leader that must not return stale data cannot serve reads from local state alone.

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