About load balancing mechanism

Here is a simple SAGA command and event handling Spring Boot program written using the axon framework. We are testing auto scale out function with this program on the K8S.
For example, start this program 5 times. So we get 5 identical microservice instances.
Than, when we request a command by “commandGateway.send”, one of 5 instances will receive and process this command.
Afterwards, if we repeatedly request this same command, it will be automatically load balanced across 5 instances and processed.
This is a very nice feature of axon because developers don’t have to consider load balancing.

I have a question.
How does axon handle this load balancing internally?
Or could you please give a link to a manual with relevant information?
I’m curious about this mechanism.


Hi @JaeHeon_Kim, welcome to the forum!

First off, we are happy to hear you think this feature of Axon is nice for developers.
That’s definitely the aim of anything we include in Axon’s product suite; enabling developers to create awesome applications.

Now, on to your question about how the command handling load is shared.

Every Axon Framework application that connects to a distributed CommandBus implementation, receives several positions on a Consistent Hash ring.
The number of positions an instance has is configurable through the “load factor” and defaults to 100.

When we dispatch a command on the CommandBus, that bus implementation first deduces which node in the cluster should receive it based on the Consistent Hash ring.
To that end, it needs to place the command on the Consistent Hash ring too and find the first match on the ring with an actual application node.
The component used in Axon to base the value on is the RoutingStrategy.

The default RoutingStrategy uses the @RoutingKey annotation, a meta-annotation of the @TargetAggregateIdentifier annotation.
Through this, commands directed to an aggregate instance will consistently end up on the same application node.
Furthermore, because the Consistent Hash ring has virtually unlimited positions, any new addition or removal of a node results in a roughly fair distribution.

So, the keyword, in this case, is the consistent hash ring.
You can see an implementation of this here, by the way.

I hope this is the info you were looking for, @JaeHeon_Kim!