Stuff Yaron Finds Interesting

Technology, Politics, Food, Finance, etc.

Two Phase Commit Need Have Nothing To Do With ACID or Any Other Kind of Transaction!

O.k., it's pet peeve time. Otherwise intelligent people seem to get really confused whenever they hear "two phase commit". They immediately assume that if one is using two phase commits then one must be implementing an ACID or at least Atomic transaction. Nonsense! A two phase commit is nothing more than a coordination mechanism. It allows one to guarantee that a group of independent systems will either all perform or all not perform a particular action. Historically the 'action' was usually some kind of ACID or at least Atomic transaction. But there is nothing in two phase commits that requires or even implies any particular action, atomic, ACID or otherwise.

In fact, two phase commits are incredibly useful for the ultimate in non-ACID transactions – compensating transactions. In an ACID transaction if the attempted transaction fails then everything gets nicely cleaned up, no muss, no fuss. In a compensating transaction, on the other hand, if the action fails then an attempt is made to undo the action but with no ACID semantics. For example, if I book a flight with a travel agency and it turns out they couldn't book the flight they said they would then instead of just canceling the whole ticket (and losing their booking fee) they might rebook me on another flight that I may or may not prefer. The point being, that the 'failed' transaction (booking the agreed flight) is 'compensated' (by buying another flight) rather than rolled back in an ACID sense (by canceling the ticket and refunding the fees).

Now imagine that I want to book a whole trip myself involving a hotel, a rental car, a plane flight, etc. I could use a two phase commit protocol to allow me to first send reservation requests to each of the companies and then if I can't get reservation confirmations from everyone the two phase commit coordinator would automatically trigger a compensate command to each of the companies. Of course the compensation may not be what I like, i.e. the airline may charge me a re-booking fee, but them's the breaks in the real world.

The point is that two phase commit protocols are nothing more or less than a coordination mechanism and what they are coordinating may or may not be an ACID or Atomic transaction.

3 Responses to Two Phase Commit Need Have Nothing To Do With ACID or Any Other Kind of Transaction!

Leave a Reply

Your email address will not be published. Required fields are marked *