BLOG

Saga Pattern

Calendar Icon
April 30, 2025
7-minute read
Illustration: Saga Pattern.

Table of Contents

In modern software development—especially when it comes to distributed systems and microservices architectures—traditional transaction models such as ACID quickly reach their limits. How, then, can long-running business processes that span multiple services still be designed consistently without compromising system availability or fault tolerance?

Our internal „Platform“ working group addressed precisely this issue—and in doing so, took a closer look at the Saga pattern. This design pattern was first described in 1987 by Hector Garcia-Molina and Kenneth Salem and offers a pragmatic solution to this very challenge. It allows for the modeling of long transactions through a sequence of small, atomic transactions that can be rolled back via defined compensation actions in the event of errors.

This article provides a practical overview of the Saga pattern, presents typical use cases, and explores various implementation strategies in today's systems.

Background and Motivation

Distributed Data Storage In microservices architectures, each service manages its own database. As a result, centralized transaction control across multiple services is virtually impossible. This makes it difficult to ensure a consistent, holistic view of all the systems involved.

Long-running business processes Many business processes consist of several individual steps that span extended periods of time—ranging from minutes to several hours. Traditional transaction models are unsuitable for such processes because they tie up system resources for extended periods and are prone to errors.

Fault tolerance without global locks Global transactions spanning multiple services require locking mechanisms that limit system availability. If a partial failure occurs, it is often unclear how to handle inconsistent intermediate states.

Asynchronous Communication In modern system architectures, communication between services is often asynchronous—for example, via events or messages. This makes centralized flow control more difficult and increases the complexity of error handling.

An Overview of the Saga Pattern

The Saga Pattern was originally described in 1987 by Hector Garcia-Molina and Kenneth Salem as a transaction model for long-running processes within monolithic systems. The goal was to break down so-called long-lived transactions (LLTs) into several smaller, independent transactions. This was intended to optimize resource utilization in traditional database systems and reduce the risk of prolonged locks. Instead of a single, long-running transaction, the individual steps were to be executed atomically and, in the event of errors, rolled back through so-called compensation actions.

Today, the Saga Pattern has taken on new relevance—particularly in the context of distributed systems and microservices architectures. The basic idea remains the same: an LLT is divided into several local transactions that are executed in an isolated and atomic manner. In contrast to classic two-phase commit (2PC) procedures, execution occurs sequentially. If an error occurs, the transactions that have already been executed are rolled back through defined compensation actions. This ensures that the consistency of the overall system is maintained even without global locks.

A distributed saga typically consists of four key components:

  • Transaction Steps
    Individual actions that are performed locally within a service and do not require a global lock.
  • Compensation Actions
    Reversible actions that can be used to undo erroneous or inconsistent states.
  • Coordination
    Either centrally through a coordinator service (orchestration) or decentrally through communication between the participating services (choreography).
  • Status Tracking
    The current state of a saga is typically persisted—for example, in a process table—to ensure that errors are handled in a traceable manner and that the execution of the substeps is transparent.

This structure makes it possible to map both long-running operations in monolithic applications and complex processes in distributed architectures in a consistent, fault-tolerant, and scalable manner.

Example: Flight booking with hotel and rental car

1. Transaction Step 1: Flight Booking

  • Promotion: The flight booking service books a flight for the traveler and reserves a seat.
  • Success: The flight is successfully booked and confirmed.
  • Compensation: If the following steps fail, the flight reservation will be canceled.

2. Transaction Step 2: Hotel Reservation

  • Promotion: The hotel booking service reserves a room for the traveler.
  • Success: The room has been successfully reserved and confirmed.
  • Compensation: If the next steps fail, the hotel reservation will be canceled.

3. Step 3: Rental Car Reservation

  • Promotion: The car rental service reserves a vehicle for the traveler.
  • Success: The vehicle has been successfully reserved.
  • Compensation: If the rental car is unavailable or an error occurs, the rental car reservation will be canceled.

Procedure:

Success Run:

Error log:

Advantages and Disadvantages of the Saga Pattern

The Saga pattern offers a number of technical advantages—particularly in the context of distributed systems. At the same time, however, it also imposes specific requirements on system architecture, error handling, and business logic.

Advantages:

  • No Global Blocks
    By breaking transactions down into local ones, there is no longer a need for global locking mechanisms that span system boundaries.
  • Transaction Control Without a Distributed Commit Protocol
    Sagas circumvent the complexity and liveness issues of classic two-phase commit (2PC) protocols. This increases system availability.
  • Error Handling via Defined Compensation Paths
    Errors in sub-steps are not handled by a full rollback, but rather through explicitly modeled compensatory actions.
  • Controllable State Management
    The progress of the saga can be tracked using a persistent process table and, in the event of an error, can be resumed or reactivated as needed.

Disadvantages:

  • Complexity of the Compensation Logic
    Compensations must be designed on a case-by-case basis. They cannot be automatically derived from the forward transactions and require in-depth subject matter expertise.
  • Difficulties in Monitoring Concurrency
    Parallel or competing sagas can cause race conditions and interference that cannot be resolved automatically.
  • Eventual Consistency Instead of Immediate Consistency
    Intermediate states may be inconsistent across the system until all steps have been completed or compensated for. This is not acceptable for all use cases.
  • Lack of Transitive Isolation
    There is no cross-process transaction isolation—other processes may access inconsistent data before the saga is complete.

When It's Worth Using the Saga Pattern—and When It Isn't

The Saga Pattern offers a robust alternative to traditional transaction models in distributed system architectures. By eliminating global locks and centralized commit protocols, it improves scalability and availability—especially in microservices-based applications. At the same time, it enables controlled error handling through clearly defined compensation paths and allows for the management of long-running business processes with many sub-steps.

Suitable Use Cases

This pattern is particularly useful when:

  • Processes consist of several steps that are logically independent of one another
  • immediate consistency is not required (keyword: eventual consistency)
  • High system availability is more important than complete isolation
  • centralized coordination is not feasible or not desired (e.g., in event-driven architectures)
  • or if compensation actions are already provided for in the business logic (e.g., for cancellations, chargebacks, and reversals).

Typical use cases include booking and payment processes, order fulfillment in e-commerce systems, and user onboarding processes that involve multiple subsystems. Sagas enable the implementation of distributed transactions without requiring all participating systems to be modified or deeply integrated at the same time. Compared to 2PC, this significantly reduces the effort required for interface design and coordination. This is particularly advantageous in early project phases or during external system integration.

When Its Use Is Not Recommended

The Saga Pattern is not suitable for all scenarios. It is particularly not recommended when:

  • strict consistency across all systems is required at all times
  • Business processes are highly intertwined, and it is not possible to identify clear sub-steps
  • the compensation logic is too complex or cannot be clearly defined in technical terms
  • or when controllability is essential in the presence of concurrency (e.g., in parallel processes with hard dependencies)

Particularly in security-critical applications—such as in the financial sector or the healthcare industry—failing to ensure immediate consistency and isolation can lead to unacceptable risks.

Our Conclusion

The Saga Pattern is a valuable tool for modern, distributed systems—but it’s not a surefire solution. Success depends heavily on how it’s implemented. Those who use it must actively address the challenges of compensation, concurrency, and consistency. When used correctly, however, the pattern enables fault-tolerant, scalable, and transparently orchestrated processes in a microservices environment.

share ->

Related Articles

Home
Company