Compensating Transaction

Compensating Transactions provide a way to roll back or undo all the tasks performed in a step of series. Suppose one or more services have implemented operations in a series and one or more of them have failed. What would be your next steps then? Would you reverse all the steps or commit to a half-completed functionality?

In our case, where a customer orders a book and ProductService marks the ordered book as sold temporarily, after the confirmation of the order, OrderService calls an external service for completing the payment process. If the payment fails, we would need to undo our previous tasks, which means we will have to check ProductService so it would mark the specific book as unsold.

Get Building Microservices with .NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.