Jonatan Matajonmatum.com
conceptsnotesexperimentsessays
© 2026 Jonatan Mata. All rights reserved.v2.1.1
Concepts

Saga Pattern

Pattern for managing distributed transactions in microservices through a sequence of local transactions with compensating actions to handle failures.

seed#saga#pattern#transactions#distributed#compensation#microservices

What it is

The Saga pattern manages transactions spanning multiple microservices. Instead of a distributed ACID transaction (costly and fragile), a saga is a sequence of local transactions where each step has a compensating action in case of failure.

Types

Choreography

Each service listens to events and decides what to do:

Order created → Inventory reserved → Payment processed → Order confirmed
                                   ↓ (failure)
                            Inventory released ← Payment rejected

Orchestration

A central orchestrator coordinates the steps:

Orchestrator → Reserve inventory → Process payment → Confirm order
            ← Compensate if any step fails

Choreography vs Orchestration

AspectChoreographyOrchestration
CouplingLowMedium
VisibilityHard to traceClear flow
ComplexityGrows with servicesCentralized

When to use it

  • Transactions spanning multiple services (orders, payments, inventory)
  • When eventual consistency is acceptable
  • Long-running business processes (days or weeks)

When not to use it

  • If you can solve it with a single database — don't add unnecessary complexity
  • When you need immediate strong consistency (real-time bank transfers)
  • If fewer than 3 services are involved — probably not worth it

Design principles

  • Idempotency — each step must be executable multiple times without side effects
  • Explicit compensations — each local transaction needs its reverse defined upfront
  • Observability — without distributed tracing, debugging sagas is a nightmare
  • Timeouts — define how long to wait before considering a step failed

Why it matters

In distributed systems, ACID transactions don't cross service boundaries. The saga pattern coordinates distributed transactions through a sequence of local transactions with compensations, maintaining eventual consistency without distributed locks.

References

  • Saga Pattern — Chris Richardson. Canonical pattern reference.
  • Sagas — Hector Garcia-Molina, Kenneth Salem, 1987. The original Princeton paper.
  • Saga Pattern — Azure — Microsoft, 2024. Saga pattern implementation guide.

Related content

  • Microservices

    Architectural style structuring an application as a collection of small, independent, deployable services, each with its own business logic and data.

  • Event-Driven Architecture

    Architectural pattern where components communicate through asynchronous events, enabling decoupled, scalable, and reactive systems.

  • CQRS

    Pattern separating read and write operations into distinct models, optimizing each independently for performance and scalability.

  • Event Sourcing

    Pattern where application state is derived from an immutable sequence of events, providing complete audit trail and the ability to reconstruct state at any point in time.

  • Distributed Tracing

    Observability technique tracking requests across multiple services in distributed systems, enabling bottleneck identification and failure diagnosis.

Concepts