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
- Diego Ongaro, John Ousterhout (2014). In Search of an Understandable Consensus Algorithm.