Disclaimer: For the following part, I'm saying most, because I obviously don't have experience with all banking systems.
Just like any system which needs to be really fast, even banks are eventually consistent. When you're implementing such system, you really want it to be online as much as possible. Any possible downtime will hurt your business, because you're delaying the customer in whichever situation they currently are. And believe me, slowly responding banking system is a really awful experience also for retailers. It hurts everyone.
To stay as available and fast as possible, most ATMs and/or card terminals don't verify your balance and process the transaction against the master in real time. With the amount of transactions, that would flood the system.
The owners of banks know that, the majority of requests to withdraw money from ATM or to issue a card transaction are going to succeed. Because of this, when you do actually want to withdraw money from ATM, the machine pings the bank's very quick and scalable read model to very quickly check if you have the desired amount or not. Know that this ping is done on a replica and thus may not be in real-time sync with the master.
Once the ping is done and your status is verified, the ATM notes that you have made a withdrawal and dispenses the money. Every configured period the ATM then collects all withdrawals made and sends them to appropriate authorities.
Some ATMs might be (and usually are) more complex, remember some information about your account from the card, so that they don't have to ping the bank every time. Thanks to this, the ATM alone usually prevents you from withdrawing $500 and $500 right after when your account would only contain e.g. $501 - in this case the first withdrawal is fine, the second is not, because the ATM remembers you had $501, have withdrawn $500 so your theoretical balance is $1. Obviously, if the ATM is one of the dumber ones which ping banking association every time, the replica is still likely to reply with $501 even on the second withdrawal and even the second withdrawal will be allowed. But this is still not a problem.
Because banks actually don't mind you to go into negative balance, they even allow these temporary hiccups and implement a reporting system which notifies administrators and support in a case when someone's balance becomes negative. This in turn may trigger other processes, such as starting to bill your for the time of having a negative account balance,...
While banking might seem really strict and feels like every single operation must be consistent, availability is a much more important aspect when it comes to banking, therefore banks are programmed that way.
To answer your questions directly:
ATM gives money then send a deduction request to it's bank. What
happens, if the request will fail? the user got the money but his
account hasn't been deducted - fail.
To prevent this problem, the ATMs are implemented to record both withdrawal request (containing information about how much you want to withdraw) and event about withdrawal completion.
WithdrawalRequested event is stored, the ATM starts giving you the money. If it dies right after giving you the money but before storing the
WithdrawalCompleted event, this is not a problem.
- After a reboot the ATM will in some way sum all made successful withdrawals, subtract the sum value from original amount of money inserted into the ATM,
- The ATM will find inconsistency, that it's in fact missing $500, find all entities without
WithdrawalCompleted event, and if there's an incomplete request it [ATM] will simply complete it.
Ad 2. If the ATM is unable to find a matching withdrawal, it sends a report to authorities that this has happened and it will have to be investigated.
Now, if you do request withdrawal and the ATM dies before even recording the
WithdrawalRequested event, this is not a problem, simply nothing will happen. But if the ATM dies between storing
WithdrawalRequested and actually giving you money, as before, after reboot measurements need to be made that the request is not actually sent to authorities, once again by verifying the current state of money in the ATM - in this case the money would match amount of sum of completed withdrawals subtracted from original amount of funds and the request will be simply discarded (still possibly notifying someone that the problem has occurred).
ATM send a deduction request to it's bank, bank deduct the value, send
a request back to ATM, the request fail (disappear). the user was
deducted but hasn't got his money - fail
This situation will never happen since the ATMs do not issue the command before dispensing the money but after.