Module 16 / Consistency across services

Module 16 · lesson 4 of 8 · Read 9 min

Compensating actions

Refunds, releases and other undos that are not really undos.

In the sagas lesson, compensations looked tidy: void the authorisation, release the coupon, cancel the order. Each one neatly reverses its step.

Real compensations are messier. The world has moved on since the step ran. Some things can't be reversed at all. The undo might itself fail. And sometimes the "undo" arrives before the thing it's undoing. This lesson is about designing compensations that hold up anyway.

An undo is not a rollback

A database rollback makes it as if the transaction never happened. Nobody ever saw its changes.

A compensation can't do that. The step already committed, and other people may have seen it, used it, or acted on it. So a compensation doesn't erase history. It adds a new fact that cancels out the effect of the old one.

A compensating action is a new business action that semantically reverses an earlier step's effect. It doesn't erase the step, which stays visible in the history.

Think of how a bank handles a mistaken transfer. It doesn't delete the original entry from your statement. It adds a second entry, a reversal, with the opposite amount. Both stay on the statement forever. That's a compensation.

For Tiffin, that means:

  • Cancelling an order doesn't delete the order row. It sets status = 'cancelled' and records why and when. Support can see what happened.
  • Releasing a coupon doesn't pretend it was never reserved. The promotions service records a reservation and a release, so its reports and fraud checks can see both.