How To reference other Aggregate

Say I have Aggregate A that need a reference/communicate aggregate B.
For example a command is send to Aggregate A → validate and emit an event But I l also need to update Aggregate B due this event.

Any idea how to do it via Axon?

Hi Eyal,

While it’s possible to use Saga’s, it’s likely better to merge those aggregates if they are strongly coupled.

A Saga can be started from an event from one aggregate. Exciting a command on another. And than either close or do mitigating actions after some time, or when some other event is received. But it’s likely simpler when you can use one aggregate.

Thank you for answering me.
Aggregate A needs to be aware of changes happened within Aggregate B but they basically lives in there own bounded context.
Say for example you have shopping cart and product. Shopping cart is my Aggregate A and product aggregate B.
Say for example I added product x to my shopping cart and after a while product x is not longer being sold since it was found to be damaged. I to “notify” to my shopping cart to take out product x out of the cart ?

Since in that case the lifetimes would be quite different, that could be a valid reason to have them seperate.

You could use a Saga here, that would start whenever a ShoppingCartCreated happened. It could track the products, by also listening to ProductAddedToCard and ProductRemovedFromCard. It could have a deadline set, so offer a certain time the card would be removed. And it could listen to all ProductOutOffStock to (temporarily) remove items on such a case.

You could even fairly easily add more advanced things. Like sending a reminder if the shopping card wasn’t changed for 3 weeks.

In all these cases either an event triggers a command, which might trigger a event, which causes the state of the saga to change.

1 Like

Thank you very much I think I’ll take a look at saga pattern as I’m not so familiar with