Compensating Action

A compensating action is a new operation that corrects the business effect of an earlier committed operation when that operation cannot simply be rolled back. In payment processing, if a capture arrives after an order has already been cancelled because of a failure event, the backend issues a refund through the provider and ensures that the refund happens only once.

Minimal example

sql
INSERT INTO payment_refunds (payment_id, status)
VALUES (?, 'PENDING')
ON DUPLICATE KEY UPDATE payment_id = payment_id;

Learn this concept

Lesson 8.3 · HMAC webhooks and payment sagas

Used in exercises

Exercise 8.4 · Payment processing service