.NET Architecture & System Design Interview Question #94

What is the Saga pattern in distributed systems?

Transactions, CQRS, Event Sourcing & Distributed Consistency Mid-Level Intermediate

Quick Interview Answer

A Saga coordinates a long-running business process as a sequence of local transactions. Each step commits independently, and failures may trigger compensating actions for previously completed steps.

Detailed Explanation

A Saga coordinates a long-running business process as a sequence of local transactions. Each step commits independently, and failures may trigger compensating actions for previously completed steps.

Sagas avoid holding one distributed transaction across services, but they require explicit workflow state, idempotency, failure handling, retries, and compensation logic.

Code Example

Reserve Inventory
      |
Charge Payment
      |
Create Shipment

Failure:
Refund Payment
Release Inventory