by strzalek on 10/16/19, 11:02 PM with 65 comments
by dragonwriter on 10/17/19, 3:35 AM
> It’s impossible to split a single payment into multiple payouts, since there is a many-to-one relationship of payments to payouts.
So your model used a many-to-one relationship when you really wanted a many-to-many?
> Since this is just a SQL database, there’s nothing preventing the payouts from becoming inconsistent.
Preventing inconsistencies by enforcing constraints is a key point of an RDBMS. This is literally why people use SQL DBs.
> The payout_id can be ensured to be a valid foreign key, but nothing is stopping it from being nulled out.
You mean, like a NOT NULL constraint? Or, if you mean zeroed out, an appropriate constraint and/or before update trigger protecting the amount?
by achiang on 10/17/19, 3:11 AM
We built our own double-entry accounting engine at my previous company, and while the engine was not as fancy as what Square describes, the real challenge was building out the accounting models that manipulated the engine's primitives.
To this day, I have yet to find another resource on multi-currency that is as solid as this one:
https://www.mathstat.dal.ca/~selinger/accounting/tutorial.ht...
by inopinatus on 10/17/19, 2:59 AM
It’s also the original event-sourced conflict-free replicated data type and the joke about CRDT for your debits is a classic thigh-slapper in the exciting world of accounting software backend implementation
by Dowwie on 10/17/19, 12:06 PM
So, approach this space with a healthy dose of skepticism until its been appropriately vetted and certified by third party auditors.
by j88439h84 on 10/17/19, 1:55 AM
[1] https://docs.google.com/document/d/1RaondTJCS_IUPBHFNdT8oqFK...
by jasim on 10/17/19, 9:17 AM
But most transactional systems where things move from one entity to another and has the notion of "balance value" is best represented by the double-entry system.
When a customer purchases pre-paid balance, the phone company can record it as a "credit", and every call they make becomes a "debit". This is an immutable log - one of the earliest application of immutable data structures in human history.
In this post authors used positive and negative values to represent debit and credit - we could call it yin and yang for all it mattered. The core principle is just that every transaction has a source and destination and the ledger is an append-only table.
by UtahDave on 10/17/19, 4:15 AM
I'm a little surprised they didn't use double entry accounting from the beginning.
by adamcharnock on 10/17/19, 7:33 AM
It provides models with Postgres constraints to ensure the double entry accounting rules are not broken.
It isn’t the same scale as Books, but I imagine that won’t matter for a lot of use cases.
by nevi-me on 10/17/19, 8:35 AM
> To address consistency, we picked a well-established, public-domain, battle-tested approach to modeling financials that enables all of our properties ...
I think doing anything other than double-entry leads to reinventing the wheel. When a ledger system is implemented correctly, the main remaining issue becomes scalability.
by wolfspider on 10/17/19, 4:35 AM
by andriosr on 10/17/19, 12:40 PM
Updating the current balance of big merchants, which are receiving multiple payments per second seems to create a lot of lost transactions, with the locking of the balance.
That would generate deadlocks in RDBMSs, curious to know if Spanner is able to scale it.
I built a similar system using DynamoDB and optimistic locking, and for that I had to remove concurrency of updates in the same document, meaning you can get ˜30 updates of the same document per second, with each update taking ˜30 milliseconds.
by z3t4 on 10/17/19, 6:26 AM
by joshuakelly on 10/17/19, 1:11 AM
by markdown on 10/17/19, 1:09 AM
by stdbrouw on 10/17/19, 9:41 AM
For those of you reading this who wish to implement a simple system for double-entry accounting, do it like this instead: specify `debit` and `credit` columns with a foreign key to a particular account (what Square calls a "book"), and a field for the `amount`. When, later, you want to calculate the balance of an account, take the sum of all transaction `amount` where `debit = <account>` and subtract the sum of all transaction `amount` where `credit = <account>`.
by tdhoot on 10/17/19, 3:36 AM
by dhruvkar on 10/17/19, 3:02 AM
[1] https://www.waveapps.com/ [2] https://play.google.com/store/apps/details?id=com.waveaccoun...
by limeman on 10/17/19, 4:44 AM
by codedokode on 10/17/19, 8:42 AM
by CDokolas on 10/17/19, 10:10 AM
...at last ;)
by tantalor on 10/17/19, 2:05 AM
by jhoechtl on 10/17/19, 6:41 AM
by banq on 10/17/19, 3:05 AM
by jldugger on 10/17/19, 1:31 AM
Man, don't fuck up.