Requirements-driven transaction boundaries set transaction scope according to an operation’s requirements rather than organizing transactions uniformly around each operation or domain module. Choose the collaboration and transaction strategies together: synchronous invocation and observation fit a single transaction, while asynchronous messaging splits an operation into multiple transactions. section 6.2.4
For a cross-domain operation, compare the operational needs and consequences of each approach:
- A single ACID transaction is the simplest option in a monolith, but it may not fit an operation whose collaboration divides work across transactions. section 6.2.4
- A Saga coordinates multiple ACID transactions. If a later step can fail after earlier updates, those updates may require compensating transactions. section 6.2.4
- Compensation is not always needed: if business rule violations can occur only within an earlier transaction, a later transaction may need none. section 6.2.4
Creating an order
The operation may create an order, reserve credit, and send a confirmation across Order, Consumer, and Notification Management. A Saga can separate these steps into transactions; if credit reservation fails after order updates, the Order module compensates for its changes. section 6.2.4
Figure 6.20 The createOrder() operation is implemented as a Saga, which consists of a sequence of ACID transactions in each of the three subdomains. Because reserving credit can fail, the Order Domain Module must use a compensating transaction to undo any updates that it did before invoking the Consumer Domain Module.
Shows a createOrder Saga and the compensating transaction used when credit reservation fails. section 6.2.4
