What is a compensating transaction and how does it differ from a traditional database rollback?

Last updated 3 July 2026

  • A compensating transaction is a new business action that semantically undoes an already committed operation (refund a charge, cancel a reservation). It is used in Sagas when you can't hold locks across services.

  • A DB rollback is atomic and automatic: the change never committed, so no one saw it. Compensation runs after commit, when the change was already visible and possibly acted on.

  • Compensations must be idempotent and run in reverse order. Uncompensatable steps (like sending an email) should come last.

  • https://www.geeksforgeeks.org/system-design/top-microservices-interview-questions/
  • https://www.geeksforgeeks.org/system-design/microservices-resilience-patterns/
  • https://medium.com/@RichaShukla2111/saga-pattern-a-practical-guide-to-distributed-transactions-in-microservices-f4f0f27755f0
  • https://dev.to/athulmr/making-rest-microservices-resilient-bulkhead-retry-circuit-breaker-in-practice-1mpl
  • https://blog.bytebytego.com/p/6-more-microservices-interview-questions
All Microservices interview questions