A compensating transaction is a transaction that undoes the effects of a series of steps that have already been committed. It is used primarily in the SAGA pattern to revert state if a long-running workflow fails.
Booking a Flight and Hotel. If the Hotel booking fails, a Compensating Transaction is triggered to Cancel the Flight booking which was already committed.
# Code Concept for Compensating Transactions\n# This pattern is architectural.\n\nclass Service:\n def execute(self):\n # Implementation logic\n pass