by edwintorok · 12y ago · 0 comments
I noticed that (some?) ATMs around here tend to implement this flawed algorithm, paraphrasing the article:
0. database.begin()
1. mybalance = database.read("account-number")
2. newbalance = mybalance - amount
3. database.write("account-number", newbalance)
4. database.commit()
5. dispense_cash(amount)
At first sight this might seem ACID, but its not. Consider what happens if the ATM is out of cash: step#5 fails, but the money was already withdrawn from your account!It doesn't automatically revert the transaction either: you have to go to a branch office and ask for the transaction to be reverted. So much for atomic transactions at ATMs.
5. Dispense cash
6. Wait a minute or so
7. Retract cash
where 7 did not lead to a credit on my account until several days after I reported the problem to my bank. That's probably by design, however, since otherwise the machine would require automated defenses against surreptitious replacement of dispensed bills with counterfeits.Your example could be a similar failsafe against cases where the machine fails to properly dispense cash in a manner that nevertheless allows the cash to be retrieved. Otherwise you have to carefully separate errors that can't possibly lead to cash being dispensed (e.g., hopper empty) vs. those that might (e.g., bills jammed somewhere in the dispenser mechanism).
As you suggest, a customer initiated account credit is necessary to prevent fraud, and the failure to dispense claim can be verified against the host transaction log.