Tuesday, January 18, 2005

The [ACID] transaction is dead; long live the [compensating] transaction

For what seems like forever, developers have learnt about ACID transactions and the "two-phase commit". Like database normalisation, it's just something that everyone needs to know. The "Hello World" of transactions is the bank transfer. If you move money between two accounts, then the debit from the source and the credit to the destination must be completed as an ACID transaction - otherwise someone loses out. Fact.

The birth of the message-centric, asynchronous, loosely-coupled (any more buzzwords?) "service" model has serious implications for the traditional transaction, as it has become impossible to coordinate transactions across service boundaries, over long periods of time. Hence the concept of the "compensated" transaction. If your action fails, then use some kind of compensating process to undo whatever you'd started. (This is easier said than done - as someone once pointed out, if the initial process launches a missile, compensating for it is tricky.)

I now have incontrovertable proof that the two-phase commit is dead; long live the compensating transaction.

I have seen a number of strange payments over recent months from my mortgage company to my current account, matching the amount that I pay them at the beginning of every month. The mortgage company couldn't find any standing order, and once I'd convinced myself that they weren't simply giving me the money, I investigated further. It turns out that I'd not updated the bank account details when I changed mortgage, and that my monthly debit was being paid to a non-existant bank account. However, rather than reject the payment, raise an alert to someone, and sort the problem out, their systems were simply repaying the money about 7 days after the initial payment. This had been going on for about 6 months!

God alone knows where the money went in the missing days, as no one took responsibility for it (and were not therefore earning interest on it.) I also incurred an overdraft penalty during that period. Since I had expected the debit transfer to occur in any case, I don't really have an argument for personal compensation on this one, but it raises an interesting point!

No comments: