Hi, for years we have been using Axon 2 Sagas with an event bus that is kafka-enabled*. But now we are going from one to two servers for blue/green deployments and I’m at a loss if there is a way to make this work for one primary reason: how to make sure we don’t have an instance of a Saga active on two JVMs at the same time. I think this would be a problem for micro-services, too.
*By kafka-enabled, I mean that our domain events are published out to Kafka and a kafka consumer pulls those events back in to Axon. When event durability and sequencing are required, such a design simplifies error handling when a broker fails during event publishing. The command will simply fail with no events having been published, rather than succeeding with events written to the Axon EventStore but not published.
Using the OrderManagementSaga example with Kafka, there could be topics for each of the Aggregates: Order, Shipment, Invoice, etc. and each of those topics would have multiple partitions, split out by key.
Let’s say that an instance of OrderManagementSaga needs to associateWith() events that are keyed by “foo-order” and “foo-shipment”.
When there is a single-server, the SagaManager can easily single-thread across the kafka partitions. With multiple servers and each server getting a “random” share of the kafka topic-partitions, there is a good chance each server is consuming from the wrong topics needed in order to keep processing single-threaded.
server “green”
consuming from Order topic partition 0 (key: foo-order)
consuming from Shipment topic partition 1 (key: bar-shipment)
server “blue”
consuming from Order topic partition 1 (key: bar-order)
consuming from Shipment topic partition 0 (key: foo-shipment)
Can anyone give some advice on how to handle this in Axon 2? Thanks for reading.