Compensation
The process of handling failures in distributed workflows by emitting events that undo or mitigate effects of prior events.
When Compensation Occurs
- Saga issues command to target aggregate
- Target aggregate rejects the command
- RejectionNotification sent to originating saga
- Saga's source aggregate receives notification
- Source aggregate emits compensation events
Flow Diagram
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Order │ │ Saga │ │ Inventory │
│ Aggregate │ │ │ │ Aggregate │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
│ OrderCreated │ │
├──────────────────►│ │
│ │ ReserveStock │
│ ├───────────── ─────►│
│ │ │
│ │ REJECTED │
│ │◄──────────────────┤
│ │ │
│ RejectionNotif │ │
│◄──────────────────┤ │
│ │ │
│ OrderCancelled │ │
│ (compensation) │ │
SagaCommandOrigin
Tracks information needed for compensation routing:
- Saga name
- Triggering aggregate (domain, root)
- Triggering event sequence
Revocation
Response from compensation handlers indicating how to proceed:
- Continue with compensation
- Abort compensation flow
- Escalate to DLQ