On the Use of Transactions
The use of transactions in software systemsSystemA set of interconnected components that work together to achieve a specific purpose or function. is quite a fundamental and non-trivial issue. Every one knows the obvious example of retrieving money from a cash machine. Either your account is debited and you receive the money, or none of the above happens. In case the machine fails to dispense the money, the transaction requires a rollback of the debiting. However, it is not always that straightforward. Though the use of transactions providing automated rollbacks is often desirable to end-users and systemSystemA set of interconnected components that work together to achieve a specific purpose or function. analysts, it may well be unnecessary complicated or even plainly impossible to implement for the software developer.
In order to enable scaling and to avoid deadlocks, transaction processing systemsSystemA set of interconnected components that work together to achieve a specific purpose or function. typically deal with large numbers of small things, and strive to come in, do the work, and get out. This means that it is in general not feasible to use technical transactions to provide end-to-end transactional integrity for customer transactions. For instance, guaranteeing the customer transaction of a money transfer is in general not implemented through a technical transaction encompassing the debiting of the source bank account and the crediting of the destination bank account, which may reside in another bank across the globe. It is typically guaranteed by taking the transfer request as fast as possible into a secure database, followed by a number of sequential processing steps or individual transactions. This flow may even require human intervention to make sure that the customer transaction, i.e., the transfer request stored in the secure database, is executed properly.
The use of end-to-end technical transactions would often cause lots of problems in the real world. For instance, defining a technical transaction around the reservation of a flight ticket, a rental car, and a hotel room, could seem desirable to indulge the customer, but would soon lead to the simultaneous locking of all reservation systemsSystemA set of interconnected components that work together to achieve a specific purpose or function. around the world. Avoiding such deadlocks is closely related to the NS theorem Separation of States. This theorem states that after every task or action, the result state should be stored in a corresponding and appropriate data entity. This will enable the independent execution, and therefore evolution, of the implementation of the processing task, and the error handling of the task. Besides better evolvability, this strategy improves the tracing and handling of errors, and reduces the chances of having locked resources.
Another often overlooked issue in transaction management is the complexity of the rollback. While a previous write operation in the same database could be compensated by a relatively simple rollback, developers would have to implement dedicated compensating transactions in case the various steps imply changes across different systemsSystemA set of interconnected components that work together to achieve a specific purpose or function.. These compensating actions are not always straightforward or even possible. For instance, in case one of the steps has triggered a physical action, like shipping a product or opening a switch or water tap, it is simply impossible to rollback. Unless mopping the floor is part of the compensating transaction.
These issues are also quite relevant when client systemsSystemA set of interconnected components that work together to achieve a specific purpose or function. invoke an API (ApplicationApplicationThe overarching model container grouping all components, domain logic, and configurations for an enterprise solution. Programming Interface) of a target systemSystemA set of interconnected components that work together to achieve a specific purpose or function.. Examples of such client systemsSystemA set of interconnected components that work together to achieve a specific purpose or function. are business process management systemsSystemA set of interconnected components that work together to achieve a specific purpose or function. invoking services from underlying transactional systemsSystemA set of interconnected components that work together to achieve a specific purpose or function., or user interface front-ends developed upon the service APIs provided by back-end systemsSystemA set of interconnected components that work together to achieve a specific purpose or function.. The client systemsSystemA set of interconnected components that work together to achieve a specific purpose or function. often desires a customer transaction encompassing several service calls on the target systemSystemA set of interconnected components that work together to achieve a specific purpose or function.. This requires client and target systemSystemA set of interconnected components that work together to achieve a specific purpose or function. to agree on one or multiple scenarios, that define the responsibilities and behavior at both ends. We discuss here the various possibilities.
-
The client systemSystemA set of interconnected components that work together to achieve a specific purpose or function. defines the transaction and the target systemSystemA set of interconnected components that work together to achieve a specific purpose or function. is expected to honor the transaction. By invoking some start-transaction interface, the client systemSystemA set of interconnected components that work together to achieve a specific purpose or function. expects the target systemSystemA set of interconnected components that work together to achieve a specific purpose or function. to be able to rollback everything that is being processed until the stop-transaction interface is called. This is a very tough, cumbersome, and nearly impossible requirement to fulfil for the target systemSystemA set of interconnected components that work together to achieve a specific purpose or function..
-
The client systemSystemA set of interconnected components that work together to achieve a specific purpose or function. attempts to both manage and honor the transaction. Within the scope of a desired transaction, the client systemSystemA set of interconnected components that work together to achieve a specific purpose or function. keeps track of the various changes it incurs in the target systemSystemA set of interconnected components that work together to achieve a specific purpose or function., and will rollback and/or compensate the various changes that have already been performed in case something fails.
-
The target systemSystemA set of interconnected components that work together to achieve a specific purpose or function. provides an explicit aggregated service API for certain customer transactions required by the client systemSystemA set of interconnected components that work together to achieve a specific purpose or function.. In this case, the target systemSystemA set of interconnected components that work together to achieve a specific purpose or function. attempts to manage and honor the transactional integrity for a specific set of customer transactions, thereby providing appropriate rollbacks and/or compensating actions for these specified transactions.
-
The target systemSystemA set of interconnected components that work together to achieve a specific purpose or function. provides an asynchronous request API for the aggregated customer transaction required by the client systemSystemA set of interconnected components that work together to achieve a specific purpose or function.. The submitted request will be stored immediately in the database, and the target systemSystemA set of interconnected components that work together to achieve a specific purpose or function. can start the processing flow performing the various tasks, compensating already performed tasks if required, thereby even supporting manual interventions. The client systemSystemA set of interconnected components that work together to achieve a specific purpose or function. can choose to perform other tasks while checking regularly for an answer, or opt to wait or block until the aggregated service is fully executed. The latter option would emulate a synchronous service call at the client side.