liveBook · Manning

Saga

As explained in Grokking Software Architecture

A pattern that coordinates a distributed business transaction as a sequence of local transactions with compensating actions for failures.

A saga coordinates a long-running business process as a sequence of local database transactions. When a later step fails, a compensating transaction reverses earlier work. This helps maintain consistency across services that cannot share one ACID rollback. section 12.6.1 section 12.11

A laptop and a failed payment

Inventory deducts a laptop and publishes an InventoryDeducted event. Billing receives it and attempts to charge the customer. If billing fails, it publishes BillingFailed, prompting Inventory to put the laptop back. There is no network-wide rollback button; the services clean up through a new transaction. section 12.6.1

Figure 12.5 The Saga Failure Path. Because independent Microservices cannot share a single ACID "rollback" button, they must clean up after each other. When the downstream payment fails, it triggers a Compensating Transaction, forcing the upstream Inventory service to manually reverse its work.

Follow the failure path from a rejected payment to the compensating inventory transaction. section 12.6.1

Services can coordinate through choreography, reacting to decentralized events, or orchestration, where a central manager commands the workflow. Either way, network events need reliable publication: the transactional outbox accompanies the saga to guarantee that events are published. section 12.6.1 section 12.11

How Grokking Software Architecture covers it

How deep it goes
Defines local transactions and compensation, walks through a failure, and contrasts coordination styles without providing an implementation.
Examples
Uses an inventory deduction and failed credit-card charge to illustrate restoring a laptop through compensation.
What you can do after
Evaluate and understand how a saga handles a failed distributed business transaction and why reliable event publication matters.
How it connects
Connects sagas to ACID transactions, compensating transactions, event-driven communication, and the transactional outbox.

Also explained in

Compare how 3 books explain saga →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.