Help with Implementing a Distributed Command Model in Axon Framework

Hello guys… :wave:

I am working on implementing a distributed command model using the Axon Framework and I am running into a few challenges. My current setup involves multiple instances of a command-handling service and I am using Axon Server for routing commands.

The issue I am facing is that some commands are not consistently routed to the correct instance, causing occasional state desynchronization. I have double checked the aggregate identifiers, and they seem fine. I am wondering if there’s something specific I might be missing in the configuration or if this could be related to how the Axon Server handles command routing in a distributed environment.

Here’s a bit more about my setup:

  • Axon Framework version: 4.8
  • Axon Server version: 2024.1
  • Using Spring Boot for configuration

I also check this: https://discuss.axoniq.io/t/implementing-cqrs-with-axon-multiple-datasources-and-transaction-managersalesforce-admin-course But I have not found any solution. Could anyone guide me about this? Could this be an issue with the Axon Server’s load balancing or my handling of the Command Handler annotations? I had really appreciate any pointers or examples of a similar setup that worked well for you.

Thank you so much!

Respected community member! :blush:

Hi Cosam, thank you for your question!

When using Axon Server for command distribution, if you have multiple instances capable of receiving (the same) commands, Axon will load balance command processing equally among the instances (based on the aggregate identifier).

You mention that “commands are not consistently routed to the correct instance”; if an aggregate instance is receiving one or more commands that it was not the target of, it might indicate an aggregate identifier/routing key issue/mixup.

If you can share some code snippets with the commands and aggregates/command handlers in question, that would be helpful.

Cheers,
Marc