Double-Entry Ledger
By Ankur NayakReviewed
A double-entry ledger records every movement of money as balanced debits and credits that are never edited, only appended. Because every entry has an equal and opposite side, the books always sum to zero, which turns "is our money correct?" into a check a computer can run.
How it works
In double-entry bookkeeping every transaction moves an amount from one account to another: one account is debited and another credited by the same amount. Summing all entries therefore always gives zero, and any account's balance is just the sum of its entries.
Payment companies use this as their system of record. Stripe describes its Ledger as an immutable log of events: entries already published can't be deleted or modified, only corrected by new entries after review. Adyen's accounting system writes records only through templates that are mathematically verified, so the sum of all accounting records is always zero.
Modelling intermediate states as accounts is what makes problems visible. Stripe models a payment as balances moving between states; a clearing account should return to zero once a process finishes, so a balance left behind points straight at money that is stuck or unexplained.
A single payment can produce many rows. Adyen reports about 50 accounting rows over the lifetime of a payment, which pushed its PostgreSQL accounting database to thousands of inserts per second and led it to shard accounting across several clusters.
Key points
- Every movement is a balanced debit and credit
- Append-only: fix mistakes with new entries, never edits
- Balances are derived by summing entries
- Clearing accounts should return to zero; leftovers are alerts
- Write volume grows fast: shard by account or round-robin
When to use it, and pitfalls
Use it for
- Anything that holds or moves money: wallets, marketplaces, payouts
- Systems that must prove correctness to auditors or regulators
- Reconciling your records against banks' and partners' files
Watch out for
- Storing only a mutable balance column: you lose the history needed to explain it
- Letting services write arbitrary entries; restrict them to vetted templates
- Cross-shard transfers: both sides of a movement must stay consistent
- Floating-point amounts; use integer minor units
Trade-offs
Immutable entries vs. updatable balances
Keep an append-only ledger as the source of truth and treat balances as derived views.
Pros: Full audit trail; Errors are detectable by arithmetic; Easy to replay and reconcile
Cons: Many more rows than a balance table; Corrections need their own reviewed process
Used in
Related building blocks
Frequently asked questions
Why do payment systems use double-entry bookkeeping?
Because it makes correctness checkable. Every movement has an equal and opposite entry, so the whole ledger always sums to zero and accounts that should be empty after a process must return to zero. Any difference is evidence of a bug or missing money, found by arithmetic rather than by customers.
Can you update an entry in a ledger?
Not in a well-designed one. Entries are append-only; a mistake is corrected by adding new entries that reverse or adjust it, so the history of what happened and how it was fixed is preserved for audit.