Search code examples
discoveryconsensusraft

Leader address/location in Raft


This may be a very simple question but I've not been able to find a good answer to this yet. Maybe someone can help me.

Once a leader is elected -

  1. The clients will send all requests ONLY to the leader. Is this correct?
  2. Given that the location (for all practical purposes the IP address) of the leader is dynamic, how will the client know this IP address in a cluster?

Solution

  • The client attempts to submit requests to any host in the cluster. If the client guesses wrong the server either forwards the request to the leader or returns an error with the address of who it thinks is the leader.

    The first method (forwarding to the leader) is a better experience for the client. Be sure to limit the number of forwarding hops and timeout on the client.

    The second method (error with leader address) is much easier to implement. Since the leader is typically long-lived except during troubled times, it usually only takes one retry to get the request to the leader.