5 ms·
I'm curious -- how do banks actually do this, then?
by maxfan8 3y ago
I'm curious -- how do banks actually do this, then?
- eximius 3y agoLedgers. They record a list of transactions, they don't just plus or minus the balance.
- yawaramin 3y agoBut to record a transfer with a list of transactions, you need at least two transactions, and you need to write both transactions atomically in the ledger. Otherwise you end up with the same problem.
- pstuart 3y agohttps://en.wikipedia.org/wiki/Double-entry_bookkeeping https://en.wikipedia.org/wiki/Double-entry_bookkeeping
- hakunin 3y agoThis is a checksum-like trick for manual record keeping, and isn't specifically relevant to the grandparent. It isn't required in digital world. The grandparent talks about having to write 2 separate transactions in 2 accounts in such a way that either both are successfully written, or none are written. This means that there must be transactionality between 2 services, regardless of balance being cached or not.
- indigo945 3y agoThe point is that there is no such thing as "2 separate transactions in 2 accounts" in banking. There is one global ledger that contains transaction between all accounts - if you move money from account A to account B, you append one entry to the ledger that says that some sum of money moved from A to B. Then if you need to calculate an account balance, you look at all transactions in the ledger, filter by the account ID, and calculate the total. (You can then cache this result, for performance benefits, but this changes nothing about the way it works.) This is really more like a CRDT than like transaction control. It's also where Bitcoin took its inspiration from, the blockchain is just one big ledger with some hashing on top.
- hakunin 3y agoThis is a good explanation for Bitcoin-type ledger, but as far as I understand, banks don't share a global ledger. In US they run settlements through FED, which is the closest thing to global ledger we got, but internally they keep their own separate ledgers. Fed sees settlements between banks, but allocation within a bank is done via internal transactions. If you wanted to give banks a transfer rail that allows them to communicate directly incurring liability, and later settle via FED, you would need to write a transaction in each bank's ledger.
- quickthrower2 3y agoBingo
- tbrownaw 3y agoEventual consistency is a thing. Or, are you old enough to have learned to reconcile a checkbook? Where you keep track of all the checks you write and what your balance should be, and then mark them as confirmed when they show up on your (monthly, because paper via usps) bank statements?
- throwaway290 3y agoOr you can throw both transactions into an event queue and let the worker process each whenever it gets to it. You get the point...
- zaphirplane 3y agoThen the source account could not have the funds for the transaction at the time the operation is ... transacted
- vidarh 3y agoWhich regularly happens with bank accounts - hence overdrafts.
- hakunin 3y agoThe truth is, this does happen, but you want it to happen less. Banks accept certain amount of risk due to logistical limitations, but always seek ways to reduce it.
- throwaway290 3y agoTradeoff between availability and consistency. Not to error when accepting a transaction probably makes bank good money, but showing correct numbers all the time or handling transactions larger than entire account balance probably only ever helps poor people like me who anxiously check incoming transactions at the ATM and we don't make banks lots of money. So a queue of transactions to record doesn't sound like a problem, but idk I don't work at a bank
- yawaramin 3y agoOverdrafts come with limits--hence the need for a transaction to check that we are within the limit.
- throwaway290 3y ago
- csomar 3y agoYou only need one single transaction. The value of each account is deduced from the list of transactions that happened with checkpoints (fancy caching) once in a while.
- deleted 3y ago[deleted]
- ComodoHacker 3y agoBut usually they also store current balances in a separate table, and updating them is also part of the transaction.
- tbrownaw 3y agoI believe the modern term is "event sourcing".
- HelloNurse 3y agoAnd the events include things like "refused because the destination account has ceased to exist", "refused because the currency is invalid", "refused because the amount has too many decimal digits", "refused because we are boycotting you", and so on. Anything can happen.
- hcarvalhoalves 3y agoFloat, overdraft, clearing houses.... are all examples of solving the "transaction" problem with eventual consistency.