3 ms·
All good advice. A hybrid can also be useful. In some accounting systems they have the ledger table (a list of every transaction) and also a balance table (a
by jimnotgym 7y ago
All good advice. A hybrid can also be useful.
In some accounting systems they have the ledger table (a list of every transaction) and also a balance table (a running total)
The balance table gives you fast access to a total (by account, branch etc) without having to add up the ledger (which may be very large), and upon inserting the ledger entry it is UPDATEd in place by the same amount. If this is done inside the same transaction it should be safe.
There is then a periodic audit process to lock the transaction ledger, add it up and check it against the balance.
This gives the user a full sight of the transaction history and the fast response of totals.
- specialist 7y agoSo the balance table is like a cache. I'm okay with that strategy. On my To Do list is mash up a JDBC frontend for ehcache.
- jimnotgym 7y agoYes, mostly up to date, mostly correct, fast to access, easy to prove, not the source of the truth. A pretty good analogy. In paper days you would add up your various ledgers (perhaps each in its own book, sales, purchases, cash etc) at the end of each day and check that the whole thing balanced. You didn't get to go home until it did!
- jimnotgym 7y agoThe other thing you can take from accountancy is double- entry... A toy example. Money was spent on x, so it gets charged to x account and removed from the bank. More correctly debit x-expense, credit bank. Credits are by convention negative numbers. Now no matter what happens your accounts always need to balance, ie the entire set of ledgers add up to zero. Audit checks are now trivial, if either your balances table or your transactions table do not sum to zero, alert somebody. It has been working for accountants for 2000 years! https://en.m.wikipedia.org/wiki/Double-entry_bookkeeping_system https://en.m.wikipedia.org/wiki/Double-entry_bookkeeping_sys...