LedgerCore
Double-entry accounting: postings, balances and reversals. A repeated command returns the original result, and competing withdrawals lock the accounts before the balance check.
A double-entry balance
A posting puts weights on both pans, debit and credit. The stamp comes down only when the beam is level, and a punched ticket with the same key never passes twice.
The model
Every transaction has two or more postings, and debits equal credits in each currency. Amounts are stored as 64-bit minor units; no fractional money reaches the database. Balances are derived from postings and history is never edited: a reversal is a new transaction with every side inverted.
The write path
Every request carries an idempotency key. A replay with the same key and body returns the original transaction; a different body is rejected. The affected accounts are locked in a stable order, so of two concurrent attempts to spend the last unit only one succeeds. Deferred PostgreSQL constraints check the complete posting set at commit.
Under the hood
- Double entry with a balance check per currency.
- An idempotency key behind a PostgreSQL advisory lock.
- Accounts locked in UUID order against races.
- Reversal only as a new transaction, one per original.
- Updating and deleting postings is blocked by the database.