Part 11 of 16 · Day 2 · Saga, compensation
Failure mid-process with no shared transaction
Problem and experience
A long process without a shared transaction
A mortgage is made up of steps in different services. Each has its own database and no shared transaction exists.
- Approvalhotovo
- Identityhotovo
- Accounthotovo
- Disbursementselhala
What now?
- Account exists
- Money does not
- Nobody reverts it
From practiceWhich of your processes takes days and passes through multiple systems?
TakeawayWhen a step in the middle fails, the previous ones are already done and will not revert themselves.
What it means
A distributed transaction across services is impractical in practice. Each step is committed locally and the result may be inconsistent.
Why we use it
We need a mechanism that brings the process back to an acceptable state.
When it makes sense
For long processes spanning multiple services.
Where it breaks
- Relying on failure “not happening”.
- Fixing the state by hand only after an incident.
Imagine
The payout fails after the account is opened and the contract signed. The client has an account without money.
Without a shared transaction, we have to maintain consistency at the business level.
Principle, application and exercise
The Process Manager drives the process
A saga is a sequence of local steps. For every step that can be reverted, there is a compensation.
Progress
- Process Managerholds the process state
- Identity
- Account
- Contract
- Disbursement
Compensation
- Payout failed
- Close accountAccountClosureRequested
- Account closedMortgageAccountClosed
- Process: compensated
Trade-offCompensation is not turning back time, just a business countermeasure. Put irreversible steps (payout) last. The Process Manager can turn into a monolith.
TakeawayA saga does not make a process flawless. It makes failure manageable.
What it means
The Process Manager listens to events and sends requests for the next step. On failure it triggers compensations in reverse order.
Why we use it
The process has a single place where you can see what state it is in.
When it makes sense
Long-running processes across multiple services, where a partial failure must not leave the system broken.
Where it breaks
- A compensation that itself fails with no plan.
- Closing an account that already holds money.
- A Process Manager that turns into a monolith.
Imagine
The disbursement fails. The saga asks for the account to be closed and the process ends in the “compensated” state. The client is not left with an empty account.
What cannot be undone, we do last.
Training for your team
Would you like this training for your team?
We run the training on your code and your domain problem. We agree the scope, dates and format with you.
Discuss the training →