Saga Pattern in Microservices: Orchestration vs Choreography

The saga pattern helps distributed systems stay consistent without relying on a distributed transaction. Here, you’ll see how local transactions and compensating steps work, when orchestration is a better fit than choreography, and what makes a saga reliable in production.

Hubert Olkiewicz[email protected]
LinkedIn
7 min read

The saga pattern keeps data consistent across several services without a distributed transaction. Each service commits its own local transaction. If a later step fails, the saga runs a compensating action for every step that already completed. For most business processes that span more than two or three services, a central orchestrator coordinates those steps. Choreography, where services react to each other’s events, is better kept for short, simple flows.

This guide is for technical leads and decision-makers who are designing or commissioning systems where an order, a payment, a settlement or an onboarding touches several services. It covers how a saga works, how to choose between orchestration and choreography, and what separates a saga that survives production from one that only works in a diagram.

Bitecode
Build Complex Workflows Faster
Bitecode builds tailored business software with modular components for workflow automation, financial processing and other complex enterprise needs.
Visit

TL;DR

  • A saga is a sequence of local transactions, each paired with a compensating transaction that semantically undoes it. It replaces two-phase commit across services.
  • Choreography fits 2 to 4 simple steps. Orchestration fits branching logic, many participants, or any process where someone needs to see its current state.
  • Compensations must be idempotent and run in reverse order. Without that, a retry can corrupt the data the saga was meant to protect.
  • Sagas give eventual consistency, not isolation. Intermediate states are visible, so you design for that explicitly.
  • Reliable publishing, usually through a transactional outbox, matters as much as the saga logic itself.

What problem the saga pattern solves

In a monolith with one database, an order that reserves stock, charges a card and creates a shipment is a single ACID transaction. If the charge fails, the database rolls everything back. Split that into an order service, an inventory service and a payment service, each with its own database, and that safety net disappears.

The classic answer, two-phase commit, locks resources across all participants until everyone agrees. Chris Richardson’s saga write-up frames the saga as the alternative: a reliably coordinated sequence of local transactions that finishes either with every step complete or with the completed steps undone by compensating transactions. Locking across services couples them tightly, hurts availability, and breaks down when participants are external APIs or owned by another organization.

The trade is real. You give up automatic rollback and isolation, and in return you get services that stay independent and processes that can run for seconds or for days.

Why it is called a saga

The term predates microservices by decades. A 1987 Princeton technical report by Hector Garcia-Molina and Kenneth Salem proposed it for long-lived database transactions that hold resources for hours or days and block shorter ones. A long transaction qualifies as a saga if it can be written as a sequence of transactions interleaved with others, with the system guaranteeing that either all of them complete or compensating transactions repair the partial execution. Microservices inherited the idea because they face the same shape of problem at a different scale.

How a saga works, step by step

Take an order flow with three services.

  1. Create order. The order service writes the order in a pending state.
  2. Reserve inventory. The inventory service decrements available stock.
  3. Charge payment. The payment service captures the funds.

If the charge fails, the saga does not roll back. It moves backward by issuing compensations: release the inventory reservation, then cancel the order. Each compensation is its own local transaction, committed independently.

Three details matter in practice.

Compensation is semantic, not mechanical. A charged card is compensated by a refund, and a reservation by releasing it. The original change was committed and may already have been seen by other processes, so you cannot pretend it never happened. You record a new fact that cancels its business effect.

Order matters. If forward steps run A, B, C and C fails, compensations run B then A. As one explanation of the pattern points out, undoing A first could remove a resource that B’s compensation still needs.

Some steps are not compensable. An email already sent or a wire already settled cannot be unsent. Place these steps last, after every step that can still fail, so the saga rarely needs to reverse them.

Because the pattern also allows forward recovery, a failed step can often be retried rather than compensated. Transient failures, such as a timeout from a payment gateway, usually deserve a bounded number of retries before the saga turns around.

Orchestration vs choreography

There are two ways to coordinate a saga. Both are documented at length in Manning’s Microservices Patterns, second edition, which treats choreography through events, channels and handlers, and orchestration through an explicit orchestrator and state machine.

Choreography has no central coordinator. The order service publishes an event such as OrderPlaced, the inventory service reacts and publishes its own event, and the payment service reacts to that. Each service knows which events it listens for and which it emits.

Orchestration puts the flow in one component. The orchestrator tells the inventory service to reserve stock, waits for the reply, then tells the payment service to charge. On failure it issues the compensating commands itself.

Criterion Choreography Orchestration
Coordination Events between peers Central orchestrator with explicit state
Best fit 2 to 4 simple steps Branching, conditional compensation, many participants
Visibility of saga status Reconstructed from events across services One queryable place
Coupling Services depend on each other’s events Services depend on the orchestrator’s commands
Adding a step Touches several participants Changed in the orchestrator
Main risk Hard to trace as participants grow, cyclic dependencies Orchestrator becomes a critical component and can attract business logic

The Gunnar Morling article on InfoQ states a preference for orchestration for two reasons: it gives one place that can be queried for the status of a particular saga, and it avoids point-to-point communication, so adding an intermediate step does not require changing each participant.

Our view follows from that. Choreography feels elegant with three services and becomes archaeology with eight. When an auditor, a support agent or an on-call engineer asks where a specific transaction currently stands, the answer should be a lookup, not a reconstruction from five event logs. For regulated and financial flows, that alone usually decides it.

Watch one failure mode of orchestration: the orchestrator should sequence work, not own business rules. If it starts to hold domain logic that belongs to the participants, you have rebuilt a monolith with network calls. For a wider comparison of coordination styles, see our decision guide to workflow orchestration patterns and the rubric for choosing microservices communication.

Making sagas reliable

The diagram is the easy part. Production failures come from retries, duplicates and crashes, and most of the engineering effort goes there.

Idempotency everywhere

Messages are delivered at least once, orchestrators restart, and clients retry. Every saga step and every compensation must therefore be safe to run twice. A freeCodeCamp guide to sagas in Node.js advises checking idempotency first so retried calls become no-ops, making compensations idempotent, and looking them up by saga ID. It also recommends dead-letter queues and a manual rollback path, because a failing compensation is the worst case.

A practical design: derive an idempotency key from the saga ID, the step name and the attempt, and have the receiver deduplicate against stored keys. Keep those keys longer than your longest retry window. Otherwise a late retry arrives after the key has expired and executes again. We cover the mechanics, including retention, in our guide to preventing duplicate charges with idempotency keys.

Express compensations as relative operations where you can. Incrementing stock by the reserved quantity is safe to repeat in a way that setting stock to a fixed number is not.

Idempotency everywhere

Atomic publishing with the outbox

A service that updates its database and then publishes an event performs a dual write. If it crashes between the two, the saga stalls or diverges. The usual fix is the outbox pattern: write the event to an outbox table in the same local transaction as the business change, and let a separate relay publish it. Morling’s InfoQ article describes this approach with Apache Kafka and Debezium, an open-source change data capture platform, as a foundation for orchestrated saga flows. Our own walkthrough of the transactional outbox explains when it earns its place.

Persist saga state

An orchestrator that keeps its progress only in memory cannot resume after a crash. Store the saga’s state and a log of completed steps durably, so a restarted orchestrator can pick up where it stopped and run any pending compensations in reverse order. Version that state, so a stale command from a slow retry can be rejected rather than applied to a saga that has already moved on.

Design for missing isolation

Sagas are ACID without the I. While a saga is mid-flight, other transactions can see its intermediate results. Richardson names this lack of isolation as a core drawback and says concurrent sagas can produce anomalies that need deliberate countermeasures. Common ones include:

  • Semantic locks: mark a record as pending, such as an order in PENDING state, so other processes know it may still change.
  • Commutative updates: design operations so their order does not change the result.
  • Re-reading values before overwriting them, to catch lost updates.

Tell product owners about these states early. A customer may briefly see an order that is later cancelled, and the interface should have a way to say so honestly.

Make it observable

Log every step and compensation with the saga ID and trace it across services. Timeouts need an owner: define what happens when a participant never replies, and who is alerted when a saga is stuck in compensation.

When to use a saga, and when not to

A saga fits when:

  • A business process spans several services or databases that each own their data.
  • Two-phase commit is unavailable, too slow, or inappropriate because participants are external or long-running.
  • You can define a compensating action for each step.
  • Eventual consistency is acceptable to the business.
  • Transactions may run for minutes, hours or days.

It is the wrong tool when you need strong ACID guarantees, when the whole operation lives inside one service, when compensations cannot be defined, or when the operation must look atomic to outside observers. These criteria are consistent with the saga pattern documentation from Temporal.

The most useful question comes before any of this: do the service boundaries make sense? If a saga is needed for every ordinary request, the boundaries may cut through one business transaction. A modular monolith, where modules share a database transaction inside one deployable, can remove the problem rather than manage it. We explain that path in our piece on modular monoliths for custom web applications. Sagas are for the boundaries that need to exist, not a patch for ones drawn in the wrong place.

Sagas in payments and financial flows

Financial systems show why the details matter. A cross-border payout may reserve funds, convert currency, call a banking partner and post ledger entries. Each step has a real-world compensation: release the hold, reverse the conversion, issue a return, post a correcting entry. Failures happen constantly, since partners time out, return ambiguous responses and settle late.

Three consequences follow. Use orchestration, because the status of each payment must be answerable on demand. Use idempotency on every external call, because a duplicate charge is both a customer problem and a reconciliation problem. Keep the history of every step and compensation, because it becomes your audit trail. Our practical guide to payment orchestration goes deeper on routing and recovery for payment teams.

Building this without starting from zero

A saga orchestrator, durable state, an outbox relay, idempotent handlers and monitoring are all plumbing before any business value appears. Teams that build them from scratch for a single project often spend the first months on infrastructure that looks the same in every system.

Bitecode builds custom business systems from modular, ready-made components, so a project can start with up to 60% of the baseline system already in place. The modules include a Financial Module, an Automation Module, a CRM Module and a Token Module for blockchain settlement, and the systems are audit-ready, multi-currency and available self-hosted. For workflows that coordinate several services, see our automation services and advanced cloud applications. If you are scoping a multi-service platform and want the transaction design settled early, you can start from our custom software development offer.

Bitecode

Perspective

Most saga problems we meet are not saga problems. They are boundary problems and ownership problems. Teams adopt the pattern because the diagram looks clean, then discover that nobody owns the compensation for step four, or that two services quietly depend on each other’s event formats.

Our approach is to decide the transaction model before choosing tools. Which steps genuinely need separate services? Which compensations are real business operations, with a person or a ledger entry behind them? Which steps can be placed last so they never need reversing? Answering those questions first keeps the orchestrator small and the domain logic where it belongs.

This is where a modular foundation pays off. When the financial, automation and workflow building blocks already exist, the team spends its effort on the compensation rules and failure paths specific to the business, not on rebuilding state storage and retry handling. Starting with up to 60% of the baseline system in place lets that design work happen earlier and with less risk. Client-controlled customization and self-hosted options mean the result stays something the organization can operate and audit for the long term.

Bitecode

FAQ

What is the saga pattern in simple terms?

It is a way to complete a business process that touches several services, each with its own database. Every service commits a local transaction, and if a later step fails, the saga runs compensating transactions to undo the earlier ones. The result is eventual consistency rather than the instant atomicity of a single database transaction.

Should I choose orchestration or choreography?

Choose orchestration when the process has many participants, branching logic, conditional compensation, or a need to see the status of each run in one place. Choreography works for short flows of two to four steps with few participants. Most enterprise and financial processes land on orchestration.

How is a compensating transaction different from a rollback?

A rollback erases uncommitted changes as if they never happened. A compensating transaction runs after the original change was committed and creates a new, business-level change that cancels its effect, such as a refund after a charge. Other processes may have seen the original state in between, so you design for that window.

Is a saga better than two-phase commit?

For services that own separate databases, run for a long time, or involve external APIs, usually yes, because a saga avoids distributed locks and keeps services independent. Two-phase commit can still suit a tightly controlled environment where all participants support it and strong atomicity is required.

Why do sagas need idempotency?

Messages can be delivered more than once and orchestrators can crash and retry. Without idempotent steps and compensations, a retry might charge a customer twice or release inventory twice. Idempotency keys, stored longer than the retry window, make repeated execution harmless.

Sources

Articles

Dive deeper into the practical steps behind adopting innovation.

Software delivery6 min

From idea to tailor-made software for your business

A step-by-step look at the process of building custom software.

AI5 min

Hosting your own AI model inside the company

Running private AI models on your own infrastructure brings tighter data & cost control.

Hi!
Let's talk about your project.

this helps us tailor the scope of the offer

Przemyslaw Szerszeniewski's photo

Przemyslaw Szerszeniewski

Bitecode co-founder

LinkedIn