How to actually manage sagas with multiple JVM of same app running
Should each JVM of this app use same database? Otherwise tracking tokens will not "be shared" across the same app?
How are events split among same app running for sagas? Does one saga type or saga instance always handled on same app (until it is shutdown so another instance take charge of it) ?
Or is each JVM receives events and each saga of same type will run? (and result in duplicate commands sent and errors)
Any other thing to care of?
Example of scenario: 3 same app on 3 different PC/VM. Saga of name "SagaA" which can start with EventA and end with EventB. Both events have a field "id", saga has 2 event handler to handle to events in the saga.
How will events be handled for example 3 events EventA and EventB, each with "id" of different value
Etc. Many more questions.
A Saga in Axon terms is nothing more than a specific type of Event Handler. As such, Axon will use an Event Processor to give a Saga instance its events.
Event Processors come in two flavors:
SubscribingEventProcessor
TrackingEventProcessor
You should describe a subscribing processor as "receiving the events from the EventBus
within the same JVM".
A tracking processor should be described as "pulling events from the EventStore
, keeping track of the progress through as shareable token.
The nature of your question now highly depends on which Event Processor is being used.
With a SubscribingEventProcessor
you would by definition not share the event load between different instances of the same app.
Thus, a given Saga would be loaded on any live instance, given both receive events associated to the same saga.
Needless to say, using the subscribing processor for Sagas does no work well if you are going to distributed the application running those Saga instances.
Instead, it is highly recommended to use a TrackingEventProcessor
to be the source of events for a specific Saga instance.
In doing so, any load sharing follows from the requirement that a TrackingToken
must be claimed by such a processor to be able to do any work (aka, handling events).
Thus, to share the workload of providing events from the event store to your Saga instances in Axon, you would have to do the following:
TrackingEventProcessor
for said saga typeTokenStore
, where the underlying storage mechanism is shared among all app instancesTrackingToken
for the given saga type. [EDIT] On top of this, the saga_entry
table used by the SagaStore
should also be shared among among all app instances running the given Saga typeHope this answer suffices for the "many more questions" you have @Yoann!