Compensating Transactions
Compensating transactions are follow-up operations that undo the effects of a previous action when part of a multi-step process fails, helping maintain consistency in distributed systems.
When to Use
They are essential in backend system design when global transactions aren’t possible, such as in microservices or distributed workflows. For example, travel booking, e-commerce orders, or financial transactions often need rollback steps if one service in the chain fails.
Example
If a customer’s payment succeeds but inventory reservation fails, a compensating transaction refunds the payment.
Want to sharpen your interview prep?
Explore Grokking System Design Fundamentals, Grokking the Coding Interview, or book Mock Interviews with ex-FAANG engineers for real-world feedback.
Why Is It Important
They provide resilience and data integrity in distributed systems where failures are inevitable. Instead of blocking everything with 2PC, systems remain scalable and fault-tolerant.
Interview Tips
Be ready to connect compensating transactions with the Saga pattern, contrast them with strict ACID properties, and give simple real-world analogies. This shows you understand both the concept and its trade-offs.
Trade-offs
You gain scalability and availability by avoiding global locks but sacrifice immediate consistency. It also adds design and operational complexity.
Pitfalls
Common mistakes include assuming every action can be reversed, not designing compensating steps as idempotent, or forgetting failure handling for the compensating step itself.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78