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.
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
