Bank Money Transfer

(Copied from DiningPhilosophers)

Let's say you're a bank in the middle of the U.S. and you need to do a wire transfer of money; one resource ("fork"/"chopstick") is the source account, which is located at a second bank on the west coast, and the other resource is the destination account, at a third bank on east coast.

You need to grab both resources (let's say you must have both resources simultaneously to do this transaction because of various banking laws). But the only way to get either of the resources is via a network, and the two requests, although they are issued at the same time (that is, you try to get both resources simultaneously), have no guarantees about being granted, so you may get 0, 1, or 2 resources every time you ask for 2.

And you can't change this because the resources are thousands of miles apart and are in two different databases, and you can't insist that all the banks that you're going to talk to must merge their databases into one central one.


To be specific:

I want

No matter what sort of communication glitch occurs (because of phone lines cut by backhoes, then suddenly restored by technicians), I want to make sure that it either goes through successfully, or both balances are unchanged.

In particular:

What are some ways of doing this? How do banks actually do it?


This is typically done by locking the funds in the source account (it's there, but short of aborting the transaction, it can't be accessed), and attempting to transfer the funds to the second account only after it locked. The difference which makes this easier is that they don't lock an account, they lock a block inside the account.


TwoPhaseCommit is a (supposed) solution to this problem.


CategoryConcurrency


EditText of this page (last edited May 15, 2004) or FindPage with title or text search