Fintech · 9 min read
Building a double-entry ledger that your auditors will trust
Wallet balances stored as a single mutable number will eventually drift. Here is how we design ledgers for payments, wallets and trading platforms so every rupee is accounted for.
Ananya Krishnan · 14 January 2026
Why a balance column is not enough
The first version of almost every wallet system has a users table with a balance column. A deposit adds to it, a withdrawal subtracts from it, and for a while everything looks fine. Then a retry fires twice, a webhook arrives out of order, or a support agent applies a manual adjustment, and the number no longer matches what the bank says. Worse, there is no way to explain how it got there.
Double-entry bookkeeping solves this by never storing balances as the source of truth. Instead, every movement of value is recorded as a transaction made of two or more entries whose debits and credits sum to zero. A balance is simply the sum of entries on an account, which means it can always be recomputed, audited and explained.
The core data model
A minimal ledger needs three tables: accounts, transactions and entries. Accounts represent anything that can hold value, such as a customer wallet, a payment gateway clearing account, a fee revenue account or a bank settlement account. Transactions group entries that belong to the same business event. Entries carry the account, the amount, the direction and the currency.
We store amounts as integers in the smallest currency unit, paise for INR or cents for USD, never as floating point. Each transaction is written inside a single database transaction, and a check verifies that the entries balance before commit. If they do not, the whole write is rejected.
- accounts: id, code, type (asset, liability, revenue, expense, equity), currency, owner reference
- transactions: id, idempotency key, event type, external reference, created at
- entries: id, transaction id, account id, amount in minor units, direction, posted at
- A database constraint or trigger that rejects unbalanced transactions
Idempotency and immutability
Payment systems are full of retries: clients retry on timeouts, gateways resend webhooks, and queues redeliver messages. Every transaction should carry an idempotency key derived from the business event, for example the gateway's payment ID, with a unique index on it. A duplicate attempt then fails harmlessly instead of crediting the user twice.
Entries are append-only. Mistakes are corrected with a reversing transaction that references the original, never with an UPDATE or DELETE. This is what makes the ledger auditable: the history of every account is complete, and you can answer what the balance was at any moment by summing entries up to that timestamp.
Reading balances quickly
Summing millions of entries on every request is slow, so production ledgers maintain a cached balance per account. The key is that the cache is derived, not authoritative. We update it in the same database transaction that inserts entries, using row-level locking on the account to serialise concurrent writes, and we run a periodic job that recomputes balances from entries and alerts on any mismatch.
For accounts with very high write volume, such as a platform's fee revenue account, row locking becomes a bottleneck. Common fixes are to shard the hot account into several sub-accounts and sum them on read, or to post to it asynchronously in batches while keeping customer-facing accounts synchronous.
Reconciliation closes the loop
A ledger tells you what you believe happened. Reconciliation checks that belief against the outside world. Every external account, whether a bank account, a payment gateway or a liquidity provider, should have a mirror account in the ledger, and a scheduled job should match statement lines to ledger entries by reference and amount.
Matched items are marked as settled; unmatched items land in an exceptions queue for the finance team. When the ledger, the reconciliation job and the exceptions queue work together, month-end close stops being a week of spreadsheet work and becomes a review of a short list of genuine anomalies.