Live data from Hacker News

Building a Scalable Accounting Ledger

scratchdata.com

21–30 of 40 posts

Re: Building a Scalable Accounting Ledger

#21
post #8

I didn't get the date as text and the amount as real in table transactions.

SQLite, as used in the article, has a very simple data model: 64 bit ints, 64 bit floats, and textual data. If you used a different database engine, you would probably use the datatypes it offers instead.

Re: Building a Scalable Accounting Ledger

#22

This confirms what I’ve heard repeated before: it’s easier to teach programming to an accountant than accounting to a programmer.

Plenty of articles of programmers talking about accounting to form one side of that opinion, where are the articles from accountants talking about programming to inform the other side?

Re: Building a Scalable Accounting Ledger

#23
post #18
post #2

This claims 1 and -1 is confusing, then proceeds to use the confusion. Why not use the language of the problem domain? The rules are unambiguous. An increase in assets are a DR, increase in liabilities a CR, in income a CR, in expenses a DR, in owners equity a CR. Decreases the opposite. Using 1 and -1 is nonsensical because their meaning in mathematics is fixed, while as shown by the rules above, in accounting DR/CR…

Then you get to corrective transactions, where a normal return is Sales DR 100 Bank CR 100 while an annulled sales invoice is Sales CR -100 Bank DR -100 The point of using debit/credit vs +/- is just that, the ability to have correct account turnovers with corrections, and maybe some conventional understanding of what's an expense account in debit and what's a vendor account in credit.

A return and an annulled sale are still credits and debits, respectively, when it comes to the mechanical sum being performed. The specific category of the action is higher-level information that doesn't need to appear at this level of the model.

Re: Building a Scalable Accounting Ledger

#24
post #20
post #7

Earlier quoted context omitted.

I think where this would get confusing is that a positive number would have to decrease some accounts, but increase others, right?

It does not because if you use + and - liabilities are negative and assets positive and if you add all balances the sum is zero. Actually the commercial accounting software I use works like that, it uses negative balances for liability accounts.

Exactly, it's completely unnecessary extra information that doesn't need to appear in the core data model that the user never directly sees. Extracting credits, debits, reversals, returns, etc. is all higher-level information.

Re: Building a Scalable Accounting Ledger

#25
post #5

I think the transactions table is misnamed. This is a table of posting legs. Which all must balance for a single transaction. I don't think you should get hung up on +ve-ve versus cr and Dr. When double entry was formalised negative numbers were not common and then thought errant. It is only in the eighteenth century it became normal. I enjoyed the entry. Note that you might you use different minimum fractions eg we…

How many legs are there in a transaction?

1 for a zero amount more realistically commonly 2. End of year may have one for each account do many.

Re: Building a Scalable Accounting Ledger

#26
Tangentially related, I know little about double-entry accounting and was wondering what CR and DR meant. If CR was credit, then what was DR? It's somewhat obviously debit, but why DR and not DB or some other abbreviation that uses letters in "debit"? I found a beautiful answer here [0] in the Accounting Historians Journal.

[0]: https://egrove.olemiss.edu/aah_journal/vol13/iss2/12/

Edit: I should add that CR and DR at one point in time were related to creditor and debitor. I referenced that article, because it's the journey of the author to find an answer that I enjoyed about it.

Re: Building a Scalable Accounting Ledger

#27
post #2

This claims 1 and -1 is confusing, then proceeds to use the confusion. Why not use the language of the problem domain? The rules are unambiguous. An increase in assets are a DR, increase in liabilities a CR, in income a CR, in expenses a DR, in owners equity a CR. Decreases the opposite. Using 1 and -1 is nonsensical because their meaning in mathematics is fixed, while as shown by the rules above, in accounting DR/CR…

In my scheme, 1 always means DR and -1 always means CR. I use this, rather than the strings DR/CR, so the database can more easily do arithmetic to calculate balances. In order to do that arithmetic, we multiply the account's normal (again, 1 or -1) by the direction (1, -1) to determine if the amount represents an increase or decrease.

Re: Building a Scalable Accounting Ledger

#29
post #14

Feels more as a way to introduce a product (scratch data), rather than a technical article. If you have only one entity to manage accounts for - why would you need to build an accounting engine? In other case, when you manage accounts for multiple entities, such as different "clients" or "branches" - you have millions of transactions, and a query such as "get accounts for this client" will take a long time - and you…

Two perspectives on this:

- I believe this is a good application of columnar stores (ie, Clickhouse) rather than traditional Postgres, where handling 1M transactions is really fast.

- You might still choose to use materialized views! This article is a suggestion for a table structure that powers those views.

Re: Building a Scalable Accounting Ledger

#30
post #5

I think the transactions table is misnamed. This is a table of posting legs. Which all must balance for a single transaction. I don't think you should get hung up on +ve-ve versus cr and Dr. When double entry was formalised negative numbers were not common and then thought errant. It is only in the eighteenth century it became normal. I enjoyed the entry. Note that you might you use different minimum fractions eg we…

Legs might be better name. Line items?

I think a lot of people are glossing over the fact that you not only need 1/-1 for DR/CR, but also the "normal" balance of the account to tabulate balances.

Post reply on HN