Saga pattern - AWS Prescriptive Guidance

Saga pattern

The saga pattern is a failure management pattern that helps establish consistency in distributed applications, and coordinates transactions between multiple microservices to maintain data consistency. A microservice publishes an event for every transaction, and the next transaction is initiated based on the event's outcome. It can take two different paths, depending on the success or failure of the transactions.

The following illustration shows how the saga pattern implements an order processing system by using AWS Step Functions. Each step (for example, “ProcessPayment”) also has separate steps to handle the success (for example, "UpdateCustomerAccount") or failure (for example, "SetOrderFailure") of the process.

Saga pattern

You should consider using this pattern if:

  • The application needs to maintain data consistency across multiple microservices without tight coupling.

  • There are long-lived transactions and you don’t want other microservices to be blocked if one microservice runs for a long time.

  • You need to be able to roll back if an operation fails in the sequence.

Important

The saga pattern is difficult to debug and its complexity increases with the number of microservices. The pattern requires a complex programming model that develops and designs compensating transactions for rolling back and undoing changes.

For more information about implementing the saga pattern in a microservices architecture, see the pattern Implement the serverless saga pattern by using AWS Step Functions on the AWS Prescriptive Guidance website.