Saga Pattern

Definition

The Saga Pattern is a design approach for managing distributed transactions across multiple services, ensuring data consistency and reliability.

Use Cases

Frequently Asked Questions

What's the difference between Saga Pattern and two-phase commit (2PC)?
Two-phase commit tries to make multiple services commit a transaction atomically, which often requires locking and tight coordination. A saga avoids a single global transaction: each service commits its own local transaction, and if something fails later, the system runs compensating actions to undo earlier steps. Sagas usually scale better and are more fault-tolerant in microservices, but they provide eventual consistency rather than strict atomicity.
When should I use Saga Pattern?
Use a saga when a business process spans multiple services or databases and you can’t (or shouldn’t) rely on a single ACID transaction. It’s a good fit for long-running workflows (seconds to days), high-scale microservices, and scenarios where eventual consistency is acceptable (e.g., travel booking, order fulfillment). Avoid it when you truly need strict atomicity across resources or when compensating actions are impossible or unsafe.
How much does Saga Pattern cost?
The pattern itself is free, but implementing it has costs: (1) workflow/orchestration runtime (e.g., state machine/workflow executions), (2) messaging (queues/pub-sub), (3) data storage for saga state, outbox/inbox tables, and logs, (4) compute for workers/handlers, and (5) engineering/operational overhead (testing compensations, observability, retries, and idempotency). Costs scale with the number of workflow steps, message volume, retries, and how long you retain state and logs.

Category: software

Difficulty: advanced

Related Terms

See Also