liveBook · Manning

Compensatable step

As explained in Microservices Patterns, Second Edition

A saga step before the pivot transaction whose effects may need to be undone by a compensating transaction.

A compensatable step is a saga transaction whose effects need an undo operation if a later step fails and the saga must roll back. Such steps precede the pivot transaction, the saga’s last step that can fail because of a business rule. Not every pre-pivot step needs compensation: a query, for example, may leave nothing to undo. section 9.2.2 section 11.1.1

Figure 9.4 A saga’s steps are grouped into three phases: zero or more compensatable transactions, which can be rolled back and so have a compensating transaction, a single pivot transaction, which is saga’s go/no-go point, and zero or more retriable transactions, which are transactions that are guaranteed to complete.
three phase saga

The three-phase layout shows where compensatable steps sit relative to the pivot and retriable steps. section 9.2.2

Order sagas

In the FTGO Create Order Saga, creating the order and ticket are compensatable: they can be rejected if card authorization, the pivot, fails. Verifying the consumer is a query and needs no compensation. In a Cancel Order Saga, canceling the order and releasing credit have compensating transactions to restore their prior state if delivery cancellation fails. section 11.1.1 section 9.3.1

Table 11.1 The definition of the FTGO Create Order Saga

Saga canvas

System operation:

createOrder(…​)

Step

Participant

Transaction

Compensating transaction

1

Order Service

(orderId, orderTotal) = createOrder(…​)

rejectOrder(orderId)

2

Consumer Service

verifyConsumer(…​)

-

3

Kitchen Service

createTicket(…​)

rejectTicket(…​)

4

Accounting Service

authorizeCard(…​)

-

5

Order Service

approveOrder()

-

6

Kitchen Service

approveTicket()

-

The saga definition table maps each Create Order step to its participant and any compensating transaction. section 11.1.1

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines phase placement and illustrates compensation in order sagas, including queries that need no undo.
Examples
Uses order creation and cancellation to show rejection, restoration of order state, and restoration of available credit.
What you can do after
Evaluate which pre-pivot saga steps need compensating transactions and recognize queries that need none.
How it connects
Connects compensatable steps to sagas, pivot transactions, compensating transactions, and retriable transactions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.