What is a “distributed transaction”?

Usually, transactions occur on one database server:

BEGIN TRANSACTION
SELECT something FROM myTable
UPDATE something IN myTable
COMMIT

A distributed transaction involves multiple servers:

BEGIN TRANSACTION
UPDATE amount = amount - 100 IN bankAccounts WHERE accountNr = 1
UPDATE amount = amount + 100 IN someRemoteDatabaseAtSomeOtherBank.bankAccounts WHERE accountNr = 2
COMMIT

The difficulty comes from the fact that the servers must communicate to ensure that transactional properties such as atomicity are satisfied on both servers: If the transaction succeeds, the values must be updated on both servers. If the transaction fails, the transaction must be rollbacked on both servers. It must never happen that the values are updated on one server but not updated on the other.

Leave a Comment