Distributed Transactions: The Saga Pattern
The Challenge:
You cannot use a single database transaction (ACID) across multiple microservices.
The Solution:
A Saga is a sequence of local transactions. Each service updates its own database and publishes an event or message to trigger the next step.
The "Undo" Button (Compensation):
Since you cannot "rollback" a committed database transaction, if a step fails, you must execute Compensating Transactions to undo previous changes.
Example: If "Charge Card" fails, trigger "Cancel Hotel Reservation".
This should be used sparingly due to complexity!