What is Saga Pattern?
Turkish: Saga Deseni
The Saga pattern splits a distributed business transaction into steps and uses compensating actions to preserve consistency when a step fails.
What is the Saga Pattern?
The Saga pattern splits a business transaction across multiple services into smaller steps and runs compensating actions if a later step fails. The goal is to manage consistency in distributed systems without relying on one large transaction.
For example, an order flow may charge payment, reserve inventory, and create a shipment. If shipment creation fails, the system may need to refund the payment and release the inventory reservation.
Types of Saga
- Orchestration: A central orchestrator decides which step runs next and which compensation is needed on failure.
- Choreography: Services publish events and other services react to them; there is no central controller.
Each step should be idempotent. If the same event is processed twice, the system must not create two refunds or deduct inventory twice.
Business Use
In microservice architectures, saga is used in payment, reservation, membership activation, and supply chain workflows. A traditional database transaction is strong inside one service; once services are separated, network failure, timeout, and partial success must be part of the design.
CQRS, event sourcing, and the outbox pattern are often seen alongside saga. The critical question is business-specific: “what compensation should happen in each failure case?”
Related Terms
CQRS separates commands from queries so write models and read models can be designed, scaled, and secured for different needs.
MicroserviceMicroservice architecture designs a large application as small services that can be developed, deployed, and scaled independently.