DEV Community

shikha
shikha

Posted on

BPMN Compensation Events Explained with Practical Workflow Examples

BPMN Compensation Events Explained with Practical Workflow Examples

When building workflow-driven systems using BPMN, processes often interact with multiple external systems.

For example:

Create order
Charge customer payment
Reserve inventory
Ship product

But what if inventory reservation fails after the payment has already been processed?

A simple database rollback will not work because the payment was already processed in an external system.

This is where BPMN Compensation Events become essential.

They provide a way to reverse previously completed activities in a workflow.

What is a BPMN Compensation Event?

A Compensation Event in BPMN allows a process to undo completed activities.

Instead of cancelling the whole process, the workflow engine triggers compensation handlers that reverse specific tasks.

Example mapping:

Activity Compensation
Charge payment Refund payment
Reserve inventory Release inventory
Book hotel Cancel booking

This pattern is extremely useful in long-running distributed workflows.

Types of Compensation Events

*There are two main compensation mechanisms in BPMN.
*

Compensation Boundary Event

A compensation boundary event is attached to a task.

Example:

Charge Payment

Refund Payment (Compensation)

If compensation is triggered later in the workflow, the refund task executes.

Throw Compensation Event

A throw compensation event explicitly triggers compensation.

It tells the process engine:

Execute all compensation handlers registered for completed activities.

Example: Order Processing Workflow

Consider a simple e-commerce workflow:

Create Order

Charge Payment

Reserve Inventory

Ship Product

If Reserve Inventory fails, the workflow should:

Trigger compensation

Refund the payment

This can be modeled using:

a compensation boundary event on the payment task
a refund compensation handler
BPMN Compensation vs Database Rollback
Many developers initially confuse compensation with database rollback.

Feature BPMN Compensation Database Rollback
Scope Business process Database transaction
Duration Long-running Short
Use case External systems DB operations
Implementation Compensation handlers DB engine

Compensation is especially important for distributed workflows and microservices orchestration.

Best Practices

When designing BPMN workflows:

Use compensation for long-running processes

Examples:

payment processing
booking systems
supply chain workflows
order management
Define clear compensation actions

Each critical activity should have a clear reverse operation.

Example:

Action Compensation
Charge payment Refund payment
Allocate resource Release resource
Ship product Cancel shipment
Avoid overusing compensation

Not every task requires compensation.
Use it when external systems must be reversed.

BPM Engines Supporting Compensation

Most BPM engines support compensation events:

Camunda
jBPM
Flowable
Activiti
Zeebe

Implementation details may vary depending on the engine.

Final Thoughts

Compensation events are a core concept in BPMN workflow design.

They allow developers to safely handle failures in long-running business processes.

Instead of cancelling the entire process, compensation enables a controlled rollback of business actions.

For teams building workflow solutions with Camunda, jBPM, or other BPM platforms, mastering compensation patterns is essential.

Full Guide

If you'd like a deeper explanation with diagrams and additional examples, you can read the full article here:

https://shikhanirankari.blogspot.com/2026/03/bpmn-compensation-events-guide-when-and.html

🇫🇷 French version of this article:
https://shikhanirankari.blogspot.com/2026/03/guide-des-evenements-de-compensation.html

Top comments (0)