Leader Election Strategies

Learn about different leader election strategies in a distributed system.

In a distributed environment, it is expensive if the client connects to every host. To reduce this overhead, distributed systems rely on the existence of a leader responsible for sequencing and coordinating with the rest of the hosts.

Since the leadership role is temporary and every leader will eventually fail, it must detect failures and the system has to elect a new leader to replace the failed one.

In this section, we will discuss the following leader election strategies:

  • Bully algorithm

  • Next-in-line failover

  • Candidate/Ordinary optimization

  • Ring algorithm

Bully algorithm

In the bully algorithm, each host in the distributed environment has a rank. The host with the highest rank is chosen as the leader during the election process. The algorithm is called bully because the hosts with the highest ranks always bully the ones with lower ranks.

This is the sequence of steps in a bully algorithm:

  • First, the distributed system identifies that the current leader is down.

  • Next, the system sends leader election notifications to hosts with higher identifiers.

  • The system waits for the higher-ranked hosts to respond for a specific duration. Once the time elapses, the system notifies the highest-ranked host it has heard from and elects the new leader. Then, the new leader notifies all the hosts with lower ranks.

  • If the system does not receive any response within the specific duration, it restarts the leader election.

Get hands-on with 1200+ tech skills courses.