Saga

A Saga is a pattern for executing a business transaction that spans multiple services or databases by chaining local transactions together, with compensating actions to roll back partial progress on failure. Sagas replace distributed transactions (two-phase commit) in microservice systems where global ACID across services is impractical.

How it works

A saga breaks a business transaction into a sequence of steps. Each step is a local transaction in one service. If any step fails, the saga runs compensating actions for all previously-completed steps to undo their effects. The saga ends when either all steps succeed or all compensations have run.

Two coordination styles

  • Choreography. Services react to events from other services; no central coordinator. Easier to start, harder to reason about as the saga grows.
  • Orchestration. A central saga orchestrator (a workflow engine or service) drives the sequence and decides what to do next. Easier to observe, debug, and modify; introduces one component that must be highly available.

Common workflow engines

  • Temporal, Cadence, AWS Step Functions, Camunda, Conductor, Azure Durable Functions, Restate

Subscribe to Sahil's Playbook

Clear thinking on product, engineering, and building at scale. No noise. One email when there's something worth sharing.
[email protected]
Subscribe
Mastodon