Container Design Pattern – Leader Election Pattern
Leader Election Pattern
In the Distributed system, multiple instances need to perform the same task, read/write from the same resource. In order to do so, all these instances need to elect a leader which will make sure that these instances will not have conflict. It will help in avoiding contention for shared resources.
A single instance is elected as a leader. Leader election can be done using any known/custom leader election algorithm such as ring algorithm, Paxos algorithm, bully algorithm, or some software like Apache zookeeper. While electing a leader needs to ensure a unique leader is elected and all other instances are aware of the leader. In case of termination of the leader (scenarios like scaledown which might bring down leader), the new leader election process should be quick and efficient.
- A single leader is easy to manage and more efficient.
- It allows coordination between processes using a lightweight methodology.
- It provides efficient control of shared resources.
- It helps in computing complex parallel tasks and collects results processed by them.
- It helps by increasing performance.
- The biggest disadvantage is it is a single point of failure.
- It increased the complexity of scaling up and deployment.
- Any issue with the leader election process will result in a significant performance bottleneck.
A leader helps with efficient coordination between tasks and efficient management of shared resources, at the same time we also need to ensure that it does not become a bottleneck.