Monday, July 12, 2004

Managing Transactions Across Components

Now, we have got specific components for generalized functions, we need to define our sample transaction of transferring 500 bucks from account A to account B. For simplicity, let's develop two components: one operating on account A, say CompA and the other on account B, say CompB. We will be having a third component to implement our transaction, i.e. transferring 500 bucks from account A to account B.

As we can see both of CompA and CompB do database operations, and the current scope of the sample transaction will allow them to do so. However, none of these two will be able to finalize the database updates, since one is dependent on the other. Which means, at any point of time, if any of the operations fail, the entire process needs to be rolled back and this needs to be done across CompA and CompB.

There comes the Transaction Manager, which will take care of such a complex activity of committing the whole operation or rolling back everything. Transaction Manager makes the implementation work pretty simple, i.e. in terms of writing codes. In the example above, it will be implemented by a set of two/three lines of codes in the third component, i.e. the component implementing the business logic.

Over the period of time Transaction Managers have become more and more powerful and now they are capable of handling distributed transactions as well, thus rechristened them as Distributed Transaction Coordinator.