Search code examples
algorithmdistributedconsensusraft

How does the Raft algorithm guarantee consensus if there are multiple leaders?


As the paper says:

Election Safety: at most one leader can be elected in a given term. §5.2

However, there may be more than one leader in the system. Raft only can promise that there is only one leader in a given term. So If I have more than one client, wouldn't I get different data? How does this allow Raft to be a consensus algorithm?

Is there something I don't understand here, that someone could explain?


Solution

  • this is the question I asked three years ago. Right now, I can answer the question myself.

    The key point here is that even the read operation, the client need to go through the raft protocol. If the client request the old leader, the old leader launch AppendEntry to confirm that whether it is the newest leader. It will notice that it is the old leader or the AppendEntry is timeout, then it will return to client timeout or error.