Source Events and Sagas - Compensation Transactions

The first question is about SO (actually ???), so bear with me please :)

We are developing a solution using event sources. Some of our business processes will be lengthy, so we plan to use sagas to command teams of several cumulative roots .

In my understanding, if the command issued by the saga must exit , the saga will be responsible for issuing compensation commands to all previously calculated roots of the population.

What should be the course of action if the state of the aggregate root is changed externally (i.e. by some other process / user) after it takes part in saga, but before the saga it failed, but issues a compensating command to this aggregated root?

In other words, how can you try to compensate for an event that is not the last in a particular thread of the cumulative root event (speaking in EventStore lingo)?

+5
source share
1 answer

This is a rather difficult situation, because what I see is that after your compensating record you can get an invalid AR, which will make your compensatory action invalid.

You will probably have to redesign the process so that changes to the AR are not made until you make sure that your process manager (saga) can execute. It is possible to temporarily save values ​​for later changes.

Another approach might be to prevent certain commands on your AR if it is in a certain state, which indicates that this could lead to problems for these commands. Then the user will not be able to issue these commands. The process manager will take care of this condition and any state expiration / timeouts, etc.

+2
source

Source: https://habr.com/ru/post/1232173/


All Articles