I’m using AxonFramework with AxonServer and all my aggregates are event-sourced and I’m using an in-memory saga store.
Saga performs fine if executed without interruptions, but I realized that I have a bad implementation, if a the application is restarted during Saga run.
Especially, my problem is that conditionally on on some state delivered by the events, Saga sends out commands to the aggregates which are not idempotent.
As a result the Saga resend commands during the replay of the events after the application restart - leading to an error.
I see generally several implementation ideas how to fix it:
- Make command idempotent and change the implementation in the aggregates’s command handler. This is sometime possible, but not always feasible.
- Make Saga track more state: for example, Saga could remember what commands have been sent. Especially, if saga has an in-memory store, it must react on events that result from commands being sent.
- Make Saga use persistent store… Hm somehow not nice if I rely on ES on aggregate side… Is there any support by the AxonServer for that?
- Make Saga detect it is in replay: I wonder if there is an equivalent to AggregateLifecycle.isLive() for Saga? If I just could detect, that my Saga is in replay, I would skip command sending…
What do you think? What is the best way to go?