10.1 Transaction-Based Processor
Use transactions to encapsulate atomic processesThis pattern is based on the Transaction-Based Processor by Fehling et al. [15, p. 201, 163], which in turn generalises the Transactional Client by Hohpe et al. [4, p. 431, 164] and database transactions.
10.1.1 Context
Reading data from message middleware or updating data in a database transactionally is not enough, as it must depend on an associated process.
10.1.2 Solution
The transaction is extended to encompass the associated process.
The message is only deleted from the queue once the operation is successful
The changed data is only committed to the database if the operation is successful
This extends the ACID properties of the transaction to the associated process (see fig. 27).
10.1.3 Potential issues
This pattern requires support in the message middleware and the database system.
10.1.4 Example
The distributed transaction used for handling orders in ExampleEshop uses messaging queues to reliably communicate between services and handle backlogs of messages. However, a service could still fail while processing a message, e.g. the warehouse system could crash while handling a reservation, and this reservation would be lost on a restart. To account for this, the services communicate with the broker transactionally. When receiving a message, the broker does not remove the message from the queue; it only hides it and only removes it once it confirms that the message was processed successfully.
10.1.5 Related patterns
The Transactional Outbox combines these two approaches, guaranteeing a message is sent if a database is updated (see § 10.2).