# Saga Pattern

> Split a task across services into steps. Each step has its own undo.

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** Saga, Distributed Transaction, Compensating Transaction

## Think of it like

Think of it like booking a trip step by step. If the hotel is full, you cancel the flight you booked.

## Definition

The saga pattern handles a task that spans many services. One database transaction cannot cover it all. The task is split into steps, and each service does its own step. Every step has an undo step, called a compensating action. If a later step fails, the undo steps run in reverse to put things back. The idea comes from a 1987 paper on long-running database work.

## Example

Lucy's travel site books a flight, then a hotel, then a car. The car step fails, so the saga cancels the hotel and then the flight, and the customer is not charged.

## Why it matters

In microservices there is no single transaction to roll back. Sagas are how data stays right when one step fails.

## Common mistake

Forgetting that undo is not always possible. A sent email cannot be unsent, so plan what to do next.

## Three principles

- **Steps across services.** Each does its part.
- **Every step has an undo.** A compensating action.
- **Fail, then reverse.** Undo in back order.

## Related terms

- [Microservices](https://learn.benibix.com/term/development/microservices)
- [Database Transaction](https://learn.benibix.com/term/development/transaction)
- [Message Queue](https://learn.benibix.com/term/development/message-queue)
- [Event-Driven Architecture](https://learn.benibix.com/term/development/event-driven-architecture)

---

Source: https://learn.benibix.com/term/development/saga-pattern
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
