Architecturecompensationcompensating action

Compensating transaction

Definition

A compensating transaction reverses the business effect of an earlier committed local transaction by applying a new, opposite change, rather than rolling back.

In practice

Once a step commits, other systems may have seen it, so it cannot simply be rolled back. A compensation records a new fact instead: a refund, a released reservation, a cancellation email. In a saga, compensations run in reverse order for every completed step.

Not every action can be compensated: an email already sent or a physical shipment cannot be unsent, so place such steps after the pivot. Compensations can fail too, so they must be retriable and idempotent. The end state is semantically consistent, not identical to never having run.

Example

ChargeCard(order 81, 49.90 EUR) succeeded but CreateShipment failed; the saga runs RefundCharge(charge ch_3K9) and then ReleaseStock(order 81).