SOLID & Design Patterns Interview Question #118

What is the Saga Pattern?

Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced

Quick Interview Answer

The Saga Pattern coordinates a business transaction that spans multiple independent operations or services without relying on one distributed ACID transaction. A saga consists of steps and, when necessary, compensating actions for previously completed steps.

Detailed Explanation

The Saga Pattern coordinates a business transaction that spans multiple independent operations or services without relying on one distributed ACID transaction. A saga consists of steps and, when necessary, compensating actions for previously completed steps.

Sagas can be orchestrated by a coordinator or choreographed through events. They introduce complexity around partial failure, retries, idempotency, and compensation, so they are most appropriate for genuinely distributed workflows.

Code Example

ReserveInventory
      |
ChargePayment
      |
CreateShipment

Failure after payment:
RefundPayment
ReleaseInventory