Compensating Workflow

A compensating workflow is a sequence of compensating actions that are executed in order to undo the effects of a previously executed business process. It is an approach used in distributed systems and microservices architectures to ensure that data consistency is maintained even when individual microservices fail or communication between them breaks down.

Compensating workflows are related to compensating actions and compensating transactions in that they are all mechanisms used to maintain data consistency in the face of failures. Compensating actions and compensating transactions are more specific and granular, whereas a compensating workflow is a higher-level concept that involves a sequence of compensating actions. A compensating workflow can be seen as an orchestration of compensating actions, designed to restore the system to a consistent state after a failure has occurred.

Let’s say we have a booking application where customers can buy flight tickets. The workflow for this application includes the following steps:

  1. A user creates a booking for a flight.
  2. The system deducts the payment amount from the user’s account and confirms the booking.
  3. If the payment succeeds but the booking fails due to an error (e.g., system downtime), a compensating workflow is triggered.
  4. The compensating workflow initiates a compensating transaction to refund the payment amount back to the user’s account.
  5. The compensating workflow sends an apology email to the user and offers a discount for a future booking.
  6. The compensating workflow logs the failure and notifies the development team to investigate the issue.

In this example, the compensating workflow handles the failure scenario where the booking system fails to complete the booking after deducting the payment amount. It initiates a compensating transaction to refund the payment amount, sends an apology email to the user, and logs the failure for further investigation. The compensating workflow also offers a discount to the user for a future booking to improve customer satisfaction.