What is compensation?
Compensation in BPMN is the mechanism for undoing work that has already been completed. Unlike error handling (which deals with failures during execution), compensation deals with successful steps that need to be reversed because of a later event.
Example: a travel booking process reserves a hotel, then a flight. The flight booking fails. The hotel reservation — already successfully completed — needs to be cancelled. That cancellation is compensation.
The elements
Compensation event (boundary)
Attached to the border of a task or sub-process. When triggered, it activates the compensation handler for that activity. Always non-interrupting — the activity has already completed.
Compensation handler
A task connected to the compensation boundary event via an association (dotted line). It defines how to undo the original task. "Reserve hotel" gets a handler "Cancel hotel reservation".
Compensation throw event
Triggers compensation. Can be an intermediate throw event (trigger specific compensation) or an end event (trigger all compensation for the current scope).
Transaction sub-process
A sub-process with a double border. If it completes successfully, all is well. If it is cancelled (via a cancel event), all completed activities inside are compensated in reverse order. Think of it as a database transaction — commit or rollback.
When do you need compensation?
- -Multi-step bookings — travel, events, resource reservations where partial completion requires rollback.
- -Financial processes — payment processing where a charge may need to be refunded.
- -Long-running processes — processes that take days or weeks, where traditional database transactions are not feasible.
Most simple processes do not need compensation. It is an advanced pattern for processes where "undoing" has real-world consequences (money, reservations, commitments).
Related guides
Keep learning
Frequently asked questions
What is the difference between compensation and error handling?▼
Error handling deals with failures during execution (a step fails). Compensation deals with reversal of successfully completed steps (a later step fails and earlier work must be undone).
Do I need compensation for every task?▼
No. Only tasks that produce reversible side effects need compensation handlers. A task that sends a notification does not need compensation — you cannot unsend an email.
What is a transaction sub-process?▼
A sub-process with a double border that behaves like a database transaction. If cancelled, all completed activities inside are compensated in reverse order.