Explain how the Saga pattern manages distributed transactions and how you handle a failure in the middle of a multi-service workflow with compensating transactions.
Last updated
A saga replaces a global transaction (no 2PC) with a sequence of local ACID transactions, one per service, each triggering the next.
On a mid-workflow failure, run compensating transactions in reverse (e.g.
ReleaseInventorythenCancelOrder). These are business-level undos like refunds, not DB rollbacks.Make steps and compensations idempotent and persist saga state for crash recovery. Put non-compensatable steps last or use pending states, and accept eventual consistency.