Assume there is a system with Double-Entry accounting:
I prefer the latter model with normalised Transaction
.
There are long running complex operations with many states. One large transaction affects many ext. accounts (or even many ledgers),
you can reverse (post opposite Transaction
s), add new transactions aka Fee, Penalty or redistribute money from all involved ext. account/ledgers transactions when
state changes.
Must keep references to Transactions
and don't duplicate Amount
in these process-specific tables.
More examples:
The simple example of ApplicationTransaction
is a Bet
which consist of several Pledge
s when you take some collateral from each participant. Each participant even has different assets at stake and House
can take many of them to satisfy some requirement.
I am thinking about generic ApplicationTransaction
table with D
iscriminator and many specific tables.
And ApplicationTransaction
table with State
column referencing many double-entry transactions it performs.
During lifetime of the ApplicationTransaction
it could post (make Transaction
s) on its state changes, but not always. For example Bet
takes collateral and
releases it when Bet
time is up, under some circumstances it redistributes initial amounts this operation held, but some of its states does not post.
A Lottery
(which is the most made up use-case here) could be an example of ApplicationTransaction
which affects many accounts, it starts and ends with massive "airdrop" of winnings. Each instance has its own attribute values, the properties are static.
Another use case is Trade
between two ext. accounts where House can be a middleman, must take assets from each side, move it to special LedgerAccount|XYZ|AL|Escrow|
, one per ApplicationTransaction.Type
, not per instance. Keep a record of transfers related to specific Trade
instance, could last for a while, have several states, attributes, different outcomes for ext. account holders which could be a penalty to one side and repayment to another. Without orderbook or matching engine. Such exchange process has several states, another counterparty could be involved in a dispute resolution if such State
transition happens. Both participants must flag a Trade
with something like Payment Received
(assuming the payment is done outside of the system). That's a state transition. System could charge fee from each participant.
It's not a single Transaction
entry. A group of them. For instance if I need to put some amount into escrow I can put X * Emeralds and X * Diamonds in order to date a princess. So it not only posts many (AssetType, Amount, AccountNo)
(N * assets * 2 parties) but also posts into Income
LedgerAccount
. Assume we perform a trade over a bucket of Assets
.
Could also add some table which restricts possible transitions per operation type so we can add constraints. I see it as a copy of State lookup table with extra NextState
column references itself, this way it defines a set of available states. Out of scope of this question though.
I am obviously not solving a new problem here, so the question is what is obviously wrong with my design and how correct direction would look like.
Perhaps there is still misunderstanding from my side, but I don't think that each application use-case instance should produce disposable LedgerAccounts
, because we don't create new HouseCash
per use-case Deposit
and Withdrawal
. The Deposit/Withdrawal is also fits into ApplicationTransaction
category, with few state transitions (like rejected by payment processor). In a real app you have a special tables to handle it, there is a payment method and amount, etc.
Otherwise such approach will result in hundreds of thousands of disposable LedgerAccounts
. The question is not a request to made a general purpose model of general purpose system for Universe, it's a question whether the direction is right, Not sure that we have to keep one-time accounts, as I already have stated, I see Account
and LedgerAccount
as something required to derive House reports, maintain customer accounts otherwise it looks as stupid as defining account per CPU-core on AWS EC2.