4 ms·
>Let’s say we’re a bank managing many bank accounts. Each account has a total. We get a never-ending stream of requests to move a sum of money m from an account
by fnord123 6y ago
>Let’s say we’re a bank managing many bank accounts. Each account has a total. We get a never-ending stream of requests to move a sum of money m from an account a to account b.
We all know that you should not do accounting using floating point numbers. But also, please understand that bank accounts are [append only] ledgers and the balance is a cached computation. I truly wish that we had a different example use case because this is really bad.
- the-dude 6y agoRegulators would like a word with you. Also, in theory it sounds nice, but reality is always more nuanced. I have implemented a bank-like SaaS which was regulated by our national financial regulators.
- fnord123 6y agoOf course it's more nuanced than a short HN comment. It's also more complicated than using a mutex to make changes to two values. > I have implemented a bank-like SaaS Which one? What made it bank like? How was it implemented? > which was regulated by our national financial regulators. Which country? > Regulators would like a word with you. To say what?
- the-dude 6y ago> To say what? Among other things, they require you to store the before & after balance with each transaction. As a truth value, not a cache. And now your whole premise is out of the window ( there is a bunch of practical reasons it won't work in reality too ).
- kevingadd 6y agoA string of before and after balances is still a ledger. This is distinct from just 'account, current_balance' tuples like a more typical schema would have.
- the-dude 6y agoIsn't one of the charactarising features of a ledger that it is a string of relative values instead of absolute values?
- a1369209993 6y agoNo, it is not. A ledger is a append-only data structure consisting of a list of (applied) transactions. What kind of transactions depends on what you're ledger-ing, but it certainly doesn't imply relative values (if anything the opposite, though probably not anything).
- the-dude 6y agoSo if they are not related(or relative) to one another, why are they on the same list?
- tomstuart 6y agoThis is the opposite of my point of view. I think it’s a great example because the whole point is that, while most people’s everyday experience of a bank account is as a single mutable value, the reality is far more complicated and subtle. Teaching is all about using simplified examples to convey intuition, and “you might think it’s easy to keep a single number up to date, but moving money between two accounts is fraught with danger” is a perfect demonstration.
- jeltz 6y agoMaybe for bank accounts that is true, but online casinos work pretty close to that example (except the floating point part) since we do not ever want to allow an account balance to be negative. Allowing balances to be negative would be a regulatory violation so what most online casinos do is to first lock and update the balance (or balances since there is also bonus money) while making sure it does not go into the negatives and then log transaction amount plus after balances. So for online casinos I would not say that the balance is cached. And I imagine traditional banking also has accounts which are never allowed to go into the negatives where a similar solution is required.
- chrisseaton 6y ago> I truly wish that we had a different example use case because this is really bad. Well... that’s why the article proposes a different, better example.
- fnord123 6y agoThe second example was interesting and insightful.