Data Consistency/

Saga Pattern

Lesson overview

Saga Pattern

Saga pattern for managing long-running distributed transactions.

A Saga is a sequence of local transactions where each step has a compensating action to undo it if the overall transaction fails.

SAGA Pattern

Payment Service

Order Service

Inventory Service

create order

Deduct inventory

Process payment

Saga Orchestration: In Orchestration, a central component called the Saga Orchestrator controls the entire workflow.

Clear workflow.

Easy to debug.

Centralized control.

Better for complex business logic.

Single point of failure (orchestrator).

Tighter coupling between services.

Saga Choreography: there is no central coordinator. Services communicate through events. Each service reacts to events and triggers the next step.

payment event

inventory event

PROS No central coordinator. Highly decoupled. Good for event-driven architectures. Better scalability. CONS Harder to understand workflow. Difficult debugging. Event chains can become complex.

inventory revert

order revert

Loading Saga Pattern