Back to Catalog
Cloud
azure
Compensating Transaction
Undo work performed by a sequence of steps in an eventually consistent operation
Intent & Description
The Compensating Transaction pattern undoes the work performed by a sequence of steps that collectively form an eventually consistent operation. If any step in the sequence fails, compensating transactions undo the effects of previous steps to maintain consistency. This is used instead of traditional distributed transactions.
Real-world Use Case
Use when implementing distributed transactions across services that do not support traditional two-phase commit.
Source
Advantages
- Handles distributed consistency without two-phase commit
- Works across different data stores
- Enables eventual consistency
- Suitable for long-running transactions
Disadvantages
- Complex to implement compensating logic
- No strong consistency guarantees
- Can be difficult to debug