Concurrency in Sagas


We’re using Axon 2.4 with ActiveMQ along with a JPA store and it’s working really well for us. However, we’ve stopped using sagas because we had concurrency issues with our multi-node deployment. The exact scenario is outlined as under:

  1. A saga is started in response to an event
  2. Multiple events for the same saga instance get fired
  3. The saga event listeners for these get fired and cause the saga to be loaded on multiple nodes
  4. One of the nodes fails updating the saga due to a optimistic lock exception

This would cause sagas to never complete. For this reason, we suspended the use of sagas altogether. Although this might seem a bit extreme, it was primarily because it was hard to predict in advance that saga events may not happen concurrently. Is this something that will be addressed with Axon 3.0 client pull model?


Hi Prem,

I think the primary issue of this is that both nodes contain an active SagaManager, which recieve the same events. In such a case it is recommended to ensure that only a single SagaManager recieves events, for example by enforcing that only a single consumer can be connected to a queue. In AMQP, you can use exclusive consumers for this. Not sure about the ActiveMQ alternative.

Axon 3 will not change too much about this, since you’ll still have the events published to each node. However, in a future version, we will include a distributed saga manager, which is able to ‘spread’ saga instances over multiple nodes. The pull model makes that easier to realise than the push model.