Axon and Domain Service

How Axon can solve the scenario where I want to change more than one aggregate instance in the same transaction? One classic example would be transferring money from account A to account B. Considering pure and classical DDD style I could do it by a domain service.

Thanks!

1 Like

Hi Murilo,

The short answer you can not. You can not change the state of more than one aggregate in one transaction. When transferring money from one bank account to another there is a (short) time that things are inconsistent. And when something fails during that period, compensating actions are needed. In Axon, you can use a Saga to manage that process. The Saga is responsible for the communication between the aggregates. I wrote a blog on how this works that you can find here

I hope this helps,

Yvonne

1 Like

Hi Yvonne, your answer definitely helped me.
I completely understand considering the scenarios and problems which Axon intends to solve. At the same time, I was curious if it would have some alternative.

Thanks!

There is actually an example application that illustrates your exact scenario.
See: GitHub - AxonFramework/AxonBank: Simple virtual bank application to showcase features of Axon Framework

I even made a diagram to understand the flow. HTH.

2 Likes