Back to glossary

Saga Pattern

A design pattern for managing distributed transactions across multiple services by breaking them into a sequence of local transactions with compensating actions for rollback on failure.

In a microservices architecture, a single business operation often spans multiple services, each with its own database. Traditional ACID transactions cannot span service boundaries, so the saga pattern coordinates these distributed operations through a sequence of local transactions, each with a corresponding compensating action that undoes its effects if a later step fails.

There are two main saga implementations. Choreography-based sagas use events: each service publishes an event when its local transaction completes, and the next service reacts to that event. Orchestration-based sagas use a central coordinator that explicitly calls each service in sequence and handles compensation on failure.

For AI-powered workflows, sagas are relevant when an AI decision triggers a chain of actions. An AI-powered order system might reserve inventory, process payment, schedule shipping, and send confirmation. If payment fails, the saga's compensating actions automatically release the inventory reservation and cancel the shipping request, maintaining system consistency without a distributed transaction.

Related Terms