# Compensating Transaction

> Undo work performed by a sequence of steps in an eventually consistent operation

- **Category**: Cloud
- **Subcategory**: azure
- **Canonical URL**: https://designpattern.fyi/patterns/azure_compensating_transaction/

---

## 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.


## Use Cases
Use when implementing distributed transactions across services that do not support traditional two-phase commit.





## Trade-offs


### Advantages

- Handles distributed consistency without two-phase commit

- Works across different data stores

- Enables eventual consistency

- Suitable for long-running transactions




### Considerations & Drawbacks

- Complex to implement compensating logic

- No strong consistency guarantees

- Can be difficult to debug







---
**Reference**: [Original Source](https://learn.microsoft.com/en-us/azure/architecture/patterns/compensating-transaction)

