A familiar example of distributed transactions is transferring money from one bank account to another. The transfer comprises of two separate actions involving debit of a certain sum of money, and the credit of this sum to another account. Both these steps will be a part of a single transaction. Both steps must be completed for the completion of the entire transaction. If only one of the two steps gets completed, the following possible problems are likely to arise:
Case 1 and 2 are summarized in the following table.
Step 1 | Step 2 | Result |
Completed Successfully | Incomplete connection failure | The amount has been debited from the customer's account but the payment has not been received. This causes the customer to lose money. |
Payment has not been made by the customer | The amount is credited to the seller's account | The bank loses money. |
In the above example, a single transaction should ensure that the either-or-none proposition holds true. Transactions do not always involve the transfer of funds as in the banking example just covered. Transactions are necessary for all kinds of business activities. For example, an online bookstore performs transactions that include ordering books from suppliers, transferring inventory from suppliers, updating available quantities of books accurately, charging customers appropriately for purchases and fulfilling customer orders. All of these actions, and a multitude of others, need to be executed within a single transaction.
In other words, a transaction is a unit of work performed on behalf of a single client, delimiting a related set of operations and providing scope for concurrency. Transactions guarantee consistency of a 'shared state' in the occurrence of concurrent access by isolating one client's work from another and undoing a client's work in case of a failure.