4 ms·
The usual for this would be to have a table of transactions instead of balances. The balances would be computed dynamically by summing the full transaction hist
by ufmace 6y ago
The usual for this would be to have a table of transactions instead of balances. The balances would be computed dynamically by summing the full transaction history for a particular account.
Of course this gets a bit unwieldy with large transaction histories, and has trouble with things like enforcing that you can't enter a transaction that draws a balance below zero.
- earthboundkid 6y agoIn the real world, you can totally go below zero though. It’s a race condition that they turned into a revenue opportunity.
- ufmace 6y agoWell yeah, but that just makes the business rules even more complex. That makes it more like - reject the transaction if it would move the account balance below zero, unless the account has a flag to allow overdrafts (which is over on the accounts table), in which case we allow the transaction and also enter another transaction for the overdraft fee. Probably need some more rules like max overdraft amount, max number of transactions etc. I've heard some places may also have the "let's be jerks" rule to reorder transactions to hit overdraft as soon as possible to maximize fees.