Answer is compensating transaction.
There are two groups of systems where compensating transaction may be applied:
1. In the context of a database this is often easily achieved using transaction and the commit/rollback mechanism.Compensating transaction logic could be implemented as additional on top of database supporting commit/rollback. In that case we can decrease business transaction granularity.
2. For systems without a commit/rollback mechanism available, one can undo a failed transaction with a compensating transaction, which will bring the system back to its initial state. Typically, this is only a workaround which has to be implemented manually and cannot guarantee that the system always ends in a consistent state. The system designer may need to consider what happens if the compensating transaction also fails.