Search DistillSys

Find a concept

Type at least two characters to search lessons, designs, papers, and interview prep.

Transactionsintermediate6 min read

Saga Transactions

Coordinate a long-running workflow with local commits and explicit compensation.

2–5 minute refresher
Mental model

Commit locally → continue → compensate completed steps on failure

30second
refresher
A saga breaks one cross-service transaction into local transactions. Each committed step has a compensating action, and a durable orchestrator or event choreography drives the workflow toward completion or repair.

What problem does it solve?

Long-lived work across independent services cannot safely hold database locks or depend on every participant being available at once.

How it works

  1. Define the invariant and durable workflow state.
  2. Execute one idempotent local transaction.
  3. Record the outcome and next command atomically.
  4. Retry ambiguous steps with stable operation IDs.
  5. On terminal failure, run compensations in a deliberate order and escalate irreparable cases.
Decision guide

Key trade-offs

ChoiceWhat you gainWhat it costs
OrchestrationVisible state and centralized recoveryCoordinator complexity
ChoreographyLoose service couplingHarder global reasoning
CompensationProgress without global locksTemporary inconsistency and business edge cases
What happens if?

A compensation also fails

The workflow remains in a durable recovery state and retries safely. After a policy limit, route it to human or automated reconciliation with complete history; never silently declare success.

Where it appears

  • Order fulfillment
  • Travel booking
  • Payment workflows
  • Temporal-style orchestration
Senior interview modeWhen would you choose a saga instead of two-phase commit?Show answer
Choose a saga for long-running, cross-service work where temporary inconsistency and explicit compensation are acceptable and participant availability matters more than one atomic commit point.
#saga#workflows#compensation#transactions