Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leader election initialisation for multiple roles in clustered environment

I am currently working with an implementation based on:

org.springframework.integration.support.leader.LockRegistryLeaderInitiator

Having multiple candidate roles so that only one application instance within the cluster is elected as leader for each role. During initialisation of the cluster if autoStartup property is set to true the first application instance that is initialised will be elected as leader for all roles. This is something that we want to avoid and instead have a fair distribution of the lead roles across the cluster.

One possible solution on the above might be that when the cluster is ready and properly initialised then invoke an endpoint that will execute:

lockRegistryLeaderInitiator.start()

For all instances in the cluster so that the election process starts and the roles are fairly distributed across instances. One drawback on that is that this needs to be part of the deployment process, adding somehow complexity.

What is the proposed best practice on the above? Are there any plans for additional features related? For example to autoStartup the leader election only when X application instances are available?

like image 298
Pantelis Papapoulias Avatar asked Oct 17 '25 07:10

Pantelis Papapoulias


2 Answers

I suggest you to take a look into the Spring Cloud Bus project. I don't know its details, but looks like your idea about autoStartup = false for all the LockRegistryLeaderInitiator instances and their startup by some distributed event is the way to go.

Not sure what we can do for you from the Spring Integration perspective, but it fully feels like not its responsibility and all the coordinations and rebalancing should be done via some other tool. Fortunately all our Spring projects can be used together as a single platform.

I think with the Bus you even really can track the number of instances joined the cluster and decide your self when and how to publish StartLeaderInitiators event.

like image 127
Artem Bilan Avatar answered Oct 18 '25 20:10

Artem Bilan


It would be relatively easy with the Zookeeper LeaderInitiator because you could check in zookeeper for the instance count before starting it.

It's not so easy with the lock registry because there's no inherent information about instances; you would need some external mechanism (such as zookeeper, in which case, you might as well use ZK).

Or, you could use something like Spring Cloud Bus (with RabbitMQ or Kafka) to send a signal to all instances that it's time to start electing leadership.

like image 41
Gary Russell Avatar answered Oct 18 '25 20:10

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!