The saga pattern

The saga pattern is the solution, proposed by microservice architectures to manage transactions in distributed systems.

A saga is a sequence of operations that represent a unit of work that can be undone by the compensation action. When an operation is successful, it publishes a message or event to trigger the next local transaction in the saga; otherwise, the saga executes a series of compensating transactions that undo the changes that were made by the preceding. Each operation can be seen as a local transaction; so, it performs a commit or rollback to its own data source, but communicates with all other operations or local transactions that build the saga.

The saga guarantees that either all of the operations complete ...

Get Hands-On Cloud-Native Microservices with Jakarta EE now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.