We have a problem with modeling a scenario where one of the aggregates contains a reference to a different one and we would like to react to some events that are triggered by the second one.
Let’s imagine a simple virtual scenario where we could have:
- A list of products - where Product is an aggregate that someone can manage, add some description etc and delete it. It’s defined globally, for the whole company. Dictionary like thing.
- A shop that also is an aggregate and contains a list of products it can offer (only IDs of products).
So in this scenario, we can define a couple of products, then create a shop and add some products so a shop can offer it.
The list of products is more or less constant, some products may be added, sometimes updated but
from time to time we would like to delete a product and make sure that its also removed from all shops (because it’s no longer supported by our company).
The first thing that comes to my mind is a saga that reacts to DeleteProductEvent and asks read model for all shops that offered that product and invoke RemoveProductCommand for all of them in a loop.
However, the problem is that when my saga asks read model about all shops connected to this product, the product itself is already gone because DeleteProductEvent was already consumed by read model handlers.
I found one topic on Axon mailing group where someone shared the link below:
But I’m wondering if long-living saga that is 1:1 connected with a lifecycle of an Aggregate is something appropriate in axon framework and won’t cause e.g. performance issues.
Or maybe Is there any other approach that allows handling such bi-directional connections?