A compensating transaction is a corrective action that counteracts an earlier transaction that has already committed. In a distributed workflow, there may be no shared rollback button: each service has its own database, so undoing an earlier step requires explicit code. section 12.6.1
Putting the laptop back
Inventory deducts a laptop and publishes an InventoryDeducted event. Billing listens and tries to process the payment. If billing fails, it publishes BillingFailed, prompting Inventory to run a compensating transaction that puts the laptop back on the shelf. section 12.6.1
Figure 12.5 The Saga Failure Path. Because independent Microservices cannot share a single ACID "rollback" button, they must clean up after each other. When the downstream payment fails, it triggers a Compensating Transaction, forcing the upstream Inventory service to manually reverse its work.

Follow the failure path from a failed payment to the inventory correction. section 12.6.1
A Saga coordinates a sequence of local transactions and supplies compensating actions for failures later in the workflow. This avoids locking the entire database while the process runs, but correction must be designed explicitly; it is not an automatic rollback. section 12.6.1
Compensation can also be part of recovery from a network partition. A system may accept writes while disconnected, tolerate temporary inconsistency, and use a Saga to correct mistakes after the partition heals. If you accept that tradeoff, plan the corrective transactions before the network fails. section 7.3.5


