Saga Pattern

Learn the Saga design pattern and its usage.

Intent

This pattern removes the need for a distributed transaction by ensuring that the transaction at each step of the business process has a defined compensating transaction. In this way, if the business process encounters an error condition and is unable to continue, it can execute the compensating transactions for the steps that have already been completed. This undoes the work completed so far in the business process and maintains the system’s consistency. Other names describing the same concept as the Saga pattern are the Compensating Transaction pattern and the Long-Running Transaction pattern. We will only discuss the Saga pattern as a failure management technique.

Context and problem

To illustrate the Saga pattern we will look at a traditional use case for distributed systems. Let’s assume we have to implement a holiday booking service to book a car, a hotel room, and a flight. The service has to book all three items in one go; partial bookings are not allowed.

Get hands-on with 1200+ tech skills courses.