DEV Community

Aivars Kalvāns
Aivars Kalvāns

Posted on • Originally published at aivarsk.com on

The COST of double-entry accounting

Sometimes I think the most important paper of our times is Scalability! But at what COST?We build “web-scale” systems and get excited about how scalable they are and how we solve the problems of scale, but we do not measure the COST: Configuration that Outperforms a Single Thread. We lack reasonable, well-done single-threaded implementations for different domains. One of which is ledger and accounting.

Because of that, many get the impression that you have to go “web-scale” to reach more than 10 ledger entries per second. You do not. All you need is a well-written implementation. Better late than never, I tried to implement a simple Proof of Concept for a ledger similar to what Modern Treasury provides: https://github.com/aivarsk/django-modern-treasury-poc.

So here is a reasonable baseline: 200 ledger entries per second. You should be able to reach at least 300 entries per second by running this in parallel even for “hot accounts”. And for normal accounts, you should hit the limits of your database and network.

There’s no magic, just an understanding of how UPDATEs work in read-committed isolation level which also explains how and why optimistic locking works with databases. And here is me discovering it in FAFO approach.

P.S. This started with a challenge to implement it with a raw SQL and the errors I found there and a simpler implementation.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

If this post resonated with you, feel free to hit ❤️ or leave a quick comment to share your thoughts!

Okay