Skip to main content

Saga Design Pattern

· One min read
Sanjeev Sarda
High Performance Developer

What is a saga?

Saga design pattern

A saga is a common microservice design pattern for handling failure in a transaction that spans multiple microservices.

When a failure occurs in any of the services that are part of the overall transaction, compensating action has to be taken.


doAction();

doCompensatingAction();

The classic use case is that of an order, payment, inventory update and delivery. These steps involve a number of microservices:

classic saga example

If something goes wrong at any stage, compensating actions are taken. These can be triggered by choreography (a decentralized event driven approach) or by orchestration (a centralized process where an orchestrator is responsible for enacting the compensating actions).

classic saga example with error

Either way, one of the main issues we face when implementing the Saga design pattern is that of dirty reads - inconsistent state during a compensating action.