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 -
Yes you are right. There can be multiple leaders at the same time, but not in the same term, so the guarantee still holds. A possible situation is in a 3-server (A, B, C) cluster, A becomes elected.
The Raft algorithm divides time into smaller terms of arbitrary lengths. With each term, an election is initiated, and a leader is chosen by majority vote. In case of no majority, the term terminates without any leader. The term number increases monotonically and is exchanged in every communication.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With