Course contentsShow
← System Design
Lesson 588 of 1,91916. Distributed TransactionsFree lesson

The Saga Pattern: Motivation and Definition

Why traditional distributed transactions fail at scale and how sagas provide an alternative coordination pattern.

The Saga Pattern: Motivation and Definition

What You'll Learn

You'll understand why the saga pattern exists as an alternative to traditional distributed transactions and what it fundamentally does.

The Problem with Traditional Distributed Transactions

Remember how Two-Phase Commit (2PC) blocks all participants while waiting for everyone to respond? And how it creates a single point of failure with the coordinator? These aren't just theoretical problems—they make systems slow, brittle, and unable to scale.

In real distributed systems, especially microservices architectures, we need something better. We need a way to coordinate multi-step operations across services without locking resources and without a central coordinator that can bring everything down.

What is a Saga?

A saga is a sequence of local transactions where each step is a separate, independent transaction that commits immediately. Instead of holding locks across services and trying to commit everything atomically, each service completes its work and commits right away.

Think of it like moving apartments: instead of having one person hold keys to both places until everything is moved (2PC), you move boxes one at a time, locking and unlocking doors as needed. If something goes wrong mid-move, you have a plan to undo what you've already done.

How Sagas Handle Failures

When a step fails in a saga, you don't roll back like a database transaction. Instead, you execute compensating transactions—explicit undo operations that reverse the effects of completed steps.

For example, if booking a flight succeeds but booking a hotel fails, the saga executes a "cancel flight" compensating transaction rather than trying to rollback the flight booking within a distributed transaction.

Key Takeaway: Sagas trade atomic consistency for availability and scalability by breaking long-running distributed transactions into a sequence of local transactions with explicit compensation logic for failures.