Systems & Backend

Saga Pattern

also: compensating transactions

A distributed transaction as a chain of local ones — undo by compensation, not rollback.

A saga splits a cross-service transaction (book flight → charge card → reserve hotel) into local steps, each with a compensating action (refund, cancel). If step 4 fails, run the compensations for 1–3. Orchestrated (a coordinator drives) or choreographed (services react to events), sagas trade 2PC’s atomicity for availability — leaning hard on idempotency because steps and compensations will retry.