News for hackers. Stuff that matters.
Re:Double-Entry Bookkeeping as a Directed Graph by qznc on Wednesday April 10, 2024 @08:41AM (#39990035)
Still too complicated. It goes wrong with "Let’s add the Transaction column to our table."

Don't store the account data. Instead store the transactions. Compute the accounts from that. The table "Transactions" should have the fields: Date, Amount, SourceAccount, TargetAccount, Description.

That is how it becomes beautiful in my opinion. Unlearn this habit of thinking in accounts just because that is what you know from your bank statements. Think in cash flows.

(Ok, this is too simple for the tax use case. Sometimes transactions have multiple sources or targets. So my schema above needs to be adapted for that. My point is that the thinking should still be different.)

Re:Double-Entry Bookkeeping as a Directed Graph by Mister_Snuggles on Wednesday April 10, 2024 @10:32AM (#39991139)
> Don't store the account data. Instead store the transactions. Compute the accounts from that. The table "Transactions" should have the fields: Date, Amount, SourceAccount, TargetAccount, Description.

This is a bad design, please don't do this.

The better design is to have header and detail tables:

Header: TransactionID, Date, Description, (other fields as required, e.g., posting status, reconciliation status, etc) Detail: TransactionID, LineNumber, Account, Amount, Description, (other fields as required, e.g., reference numbers for subledgers, etc)

This allows a transaction to affect any number of accounts. In effect, the transaction ends up reflecting a business transaction which may affect many accounts.

Re:Double-Entry Bookkeeping as a Directed Graph by EvanAnderson on Wednesday April 10, 2024 @12:25PM (#39992547)
I don't think you're saying anything different than the parent poster, fundamentally. You're both saying "event-source the totals".

You're adding an abstraction to enable more flexibility and functionality. That doesn't change the fundamental event-sourced nature of totals.

Re:Double-Entry Bookkeeping as a Directed Graph by BillyTheKing on Thursday April 11, 2024 @12:08AM (#39998290)
yes, that's the gnu cash implementation (also used by formance for example) - I don't love it tbh, yes you can add multiple postings under a single transaction, but.. if you look at one of those postings, or just the transaction in general you don't directly know which posting originates from what account, you have to sorta map it based on amounts
Re:Double-Entry Bookkeeping as a Directed Graph by superzamp on Thursday April 11, 2024 @04:53AM (#39999948)
Jumping-in as I happen to know formance very well; I'm 100% agreeing with the need to know what posting originates from what account, which is why formance transaction format is essentially a container for postings, which themselves are a quantified, directed relation between exactly 2 accounts. So a transaction can indeed impact N >= 2 accounts, but a posting within a transaction will always relate exactly 2 accounts.
Re:Double-Entry Bookkeeping as a Directed Graph by EvanAnderson on Wednesday April 10, 2024 @10:15AM (#39990979)
Any time I've dealt with bookkeeping or accounting software where I find functionality like "Rebalance accounts" I become suspicious and wary. I know that the programmer has tried to be clever and keep running totals, versus calculating them the source transactions. There be dragons there.
Re:Double-Entry Bookkeeping as a Directed Graph by BillyTheKing on Thursday April 11, 2024 @12:04AM (#39998281)
imo, realistically you'll end up with both for payment-operations - just recalculating balances for accounts with millions of transactions also causes issues
Re:Double-Entry Bookkeeping as a Directed Graph by MgB2 on Wednesday April 10, 2024 @09:52AM (#39990750)
That's basically what beancount does, isn't it? You basically have all the transactions in your plaintext files, and it generates the full ledgers from those on the fly once you want to do any evaluations.
Re:Double-Entry Bookkeeping as a Directed Graph by thfuran on Wednesday April 10, 2024 @09:06AM (#39990278)
Isn't having to replay every transaction in history to query current balance rather inefficient?
Re:Double-Entry Bookkeeping as a Directed Graph by rockostrich on Wednesday April 10, 2024 @10:08AM (#39990917)
Once a period of time is reconciled then you can pre-compute whatever information you need and then you're only computing the current balance for the current period of time that hasn't been reconciled.
Re:Double-Entry Bookkeeping as a Directed Graph by inopinatus on Wednesday April 10, 2024 @12:14PM (#39992381)
Computers are astonishingly fast at summing integers.
Re:Double-Entry Bookkeeping as a Directed Graph by epcoa on Wednesday April 10, 2024 @02:25PM (#39994082)
They are not comparably astonishingly fast at retrieving that data.
Re:Double-Entry Bookkeeping as a Directed Graph by inopinatus on Wednesday April 10, 2024 @06:57PM (#39996555)
Accounting data is so compact that the word “comparably” is doing all the heavy lifting in that statement. A large accounting system certainly prefers to have large main memory, but even in the worst case scenario, we read from persistent storage at GB/sec and the processor has no trouble keeping up. You don’t have to get particularly smart to operate a billion-row ledger; only beyond that does it start to be interesting.
Re:Double-Entry Bookkeeping as a Directed Graph by thfuran on Wednesday April 10, 2024 @04:13PM (#39995231)
They're pretty fast, but if everyone writes software that does 10,000x more computation than necessary on that basis, suddenly they're slow.
Re:Double-Entry Bookkeeping as a Directed Graph by inopinatus on Wednesday April 10, 2024 @06:58PM (#39996558)
“If everyone is incompetent, all software will be bad”. Got it, thanks.
Re:Double-Entry Bookkeeping as a Directed Graph by thfuran on Wednesday April 10, 2024 @08:56PM (#39997349)
You were the one advocating for incompetence.
Re:Double-Entry Bookkeeping as a Directed Graph by inopinatus on Wednesday April 10, 2024 @09:47PM (#39997624)
That was not the incredible burn you hoped for, because it kinda suggests a lack of consideration for the practical design of a modern computer, in which memory is tiered in orders of magnitude of time latency from CPU registers on down through on-die caches and so forth, each tier effectively acting as a local cache for the next level. Writes are super expensive and bust cache lines and coherency all the way down to main memory and in many applications touch persistent storage and even introduce network latencies in distributed systems.

By contrast, ALUs are stupendously well optimized for the baseline computational task of adding up integers.

The difference between nanoseconds and milliseconds is vast. It is consequently very often cheaper to recalculate a sum using data already in cache memory than to save it and later fetch it, or (even worse) to read a value precalculated by a neighbouring computer.

Furthermore, the distinction only matters for accounting systems at high scale. For the average small business accounting, it is de minimis: your computer performs more computation when resizing a browser window than it does in recalculating an account balance from scratch.

Re:Double-Entry Bookkeeping as a Directed Graph by thfuran on Thursday April 11, 2024 @08:55AM (#40001583)
You're supposing that the whole transaction history is for some reason already in L1? Sure, in that case the extra burden of crunching some numbers is mostly irrelevant because there's almost no data and you've already paid for it. But you probably shouldn't have.
Re:Double-Entry Bookkeeping as a Directed Graph by Mister_Snuggles on Wednesday April 10, 2024 @10:34AM (#39991157)
The act of "posting" a transaction updates the ledger to reflect the current balance. Think of the ledger as "Current state" and the transactions as "how we got there".
Re:Double-Entry Bookkeeping as a Directed Graph by globular-toast on Wednesday April 10, 2024 @09:39AM (#39990608)
It's a trade off. Immutability is a big enough win to pay the price of a few extra CPU cycles. In practice it's very quick anyway. Computers are very good at adding numbers together (it's almost like it's what they were made for!). I keep all my accounts for over 12 years in one file and I still don't notice any delay when calculating balances etc.

If it does become a problem then one solution is to take sums at some point in time and start the ledger again paying each account from a contra account containing the previous balance.

Re:Double-Entry Bookkeeping as a Directed Graph by BillyTheKing on Thursday April 11, 2024 @12:10AM (#39998297)
I mean, yes for personal accounts with a couple of thousand transactions - sure. But esp. in payments or in exchanges there can be accounts with millions of transactions a day. So you get a double-whammy - those are hot-accounts which also slow down the system, recalculating the balance for those accounts each time a transaction happens isn't an option
Re:Double-Entry Bookkeeping as a Directed Graph by globular-toast on Thursday April 11, 2024 @05:46AM (#40000329)
Another way to do it is to keep the balances online. This is how something like Bitcoin works which is essentially one giant public ledger. It's a classic time/memory trade off.
Re:Double-Entry Bookkeeping as a Directed Graph by qznc on Wednesday April 10, 2024 @09:44AM (#39990669)
You can cache it. ;)
Re:Double-Entry Bookkeeping as a Directed Graph by Solvency on Wednesday April 10, 2024 @10:17AM (#39990989)
technical speaking what does 10 years of transactions look like when it's "cached" with one current year still being raw text lines? how are the two reconciled?
Re:Double-Entry Bookkeeping as a Directed Graph by airstrike on Wednesday April 10, 2024 @01:00PM (#39992976)
basically 9 years are cached and the last year is recalculated as needed. you have a source of truth for what the data looked like at moment T+9 years, you can just take as granted. and then process the transactions following that date "live" as needed
Re:Double-Entry Bookkeeping as a Directed Graph by inopinatus on Wednesday April 10, 2024 @07:24PM (#39996730)
Table rotation on a periodic (e.g. annual or financial year) basis is a common strategy, with carried-over opening balance records at the top coded to a dummy account. So the journal for the last ten years may actually be in tables journal_2013 through journal_2023. You can also then move these quiescent partitions to cheaper storage. After a few years, even to read-only archival medium. It’s not completely unknown for financial institutions to have to refer back to a paper form to audit or restate older accounts from inception.
Re:Double-Entry Bookkeeping as a Directed Graph by atemerev on Wednesday April 10, 2024 @10:35AM (#39991164)
And that is how people invented blockchain (it is slightly more complicated, particularly that each transfer should include the source address in the output, but the idea is the same). As mentioned elsewhere in the thread, we also need multiple inputs/multiple outputs for each transaction.