Try
↑ ↓ move↵ openesc close

Interview prep / Raft and consensus

Junior · Raft and consensus · System design interview question

A client sends a write to a three-node Raft cluster. Describe what happens from the request until the client gets its answer, and at which moment it is safe to say the write is durable.

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

A strong answer

The client talks to the leader. If it reaches a follower, the follower redirects it. The leader appends the command to its own log as a new entry with the current term and the next index, and writes it to disk.

It sends an AppendEntries message with the entry to both followers. Each follower checks that its log matches at the preceding index and term, appends the entry, saves it to disk and replies. As soon as one follower has replied, the entry is stored on two of three nodes, which is a majority. The leader marks it committed, applies it to its state machine and answers the client.

That is the moment it is safe to say the write is durable, and not before. At the time of the answer the entry may sit on only two machines, and that is enough because any future leader must have won votes from a majority, and any majority of three includes one of those two. The followers learn the new commit index from the next heartbeat or AppendEntries and apply the entry then.

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