How to design a payments ledger that always reconciles

Double-entry accounting, integer amounts, idempotency keys and daily reconciliation: the design choices that keep balances correct in a FinTech product.

INDI TECHNOLOGY5 min read

In most software, a bug means something looks wrong. In a payments product, a bug means money is wrong: a wallet shows a balance that doesn't exist, a refund is paid twice, or the numbers in your system don't match the bank. These problems are expensive to find later, because by the time someone notices, thousands of transactions may be affected.

The good news is that the patterns for getting this right are well known. Accountants worked out the core idea centuries ago. This article covers the design choices that matter most when you build a ledger for a wallet, marketplace, lending or payments product.

Store money as integers

Never store amounts as floating-point numbers. 0.1 + 0.2 is not exactly 0.3 in binary floating point, and those tiny errors add up across millions of transactions.

Store amounts as integers in the smallest currency unit: paise for rupees, cents for dollars. ₹1,250.50 becomes 125050. Store the currency code with every amount, and never add amounts in different currencies without an explicit conversion step that records the rate used.

Use double-entry

In a double-entry ledger, every movement of money is recorded as a transaction made of at least two entries: one account is debited and another is credited by the same total. The entries in every transaction must sum to zero.

A customer topping up a wallet with ₹500 might look like this:

Account Debit Credit
Bank clearing account ₹500
Customer wallet ₹500

When the customer pays a merchant ₹200 from the wallet, with a ₹4 platform fee:

Account Debit Credit
Customer wallet ₹200
Merchant payable ₹196
Platform fee revenue ₹4

This structure gives you three things for free:

  • Money can't appear or disappear. If a transaction doesn't balance, it is rejected.
  • Every balance is explainable. An account's balance is the sum of its entries, so you can always show exactly how it got there.
  • Internal accounts make flows visible. Clearing, fees, refunds and suspense accounts show money that is in transit or unexplained, instead of hiding it.

Make the ledger append-only

Entries are never updated or deleted. If something was wrong, you post a reversal: a new transaction that cancels the original, followed by the correct one. The history stays intact, which is exactly what auditors, support teams and regulators need.

Store balances as a cached figure if you need fast reads, but treat the entries as the source of truth. A nightly job should recompute balances from entries and alert on any difference.

Make every operation idempotent

Networks fail at the worst moments. A client sends "pay ₹200", the request times out, and the client retries. Without protection, the customer pays twice.

The fix is an idempotency key: a unique ID the client generates for each intended operation and sends with every attempt. The server stores the key with the result. If the same key arrives again, it returns the original result instead of repeating the operation. Payment providers such as Stripe use exactly this approach with an Idempotency-Key header.

Apply the same idea everywhere money moves:

  • API requests from your own apps.
  • Webhooks from payment gateways, which are often delivered more than once and sometimes out of order. Store each event ID and ignore ones already processed.
  • Background jobs for payouts and settlements, which may run again after a crash.

Handle concurrency explicitly

Two payments from the same wallet at the same moment must not both succeed if the balance only covers one. Use database transactions with row-level locks on the account being debited, or an optimistic version check that fails and retries if the balance changed. Test it with concurrent requests, not just one at a time.

Model the states of a payment

Real payments are not instant. A UPI or card payment might be initiated, pending, succeeded, failed or later reversed. Model these states explicitly and record ledger entries at the right points. Pending funds often belong in a clearing or hold account until the provider confirms them.

When a payment's status is unclear after a timeout, don't guess. Query the provider for the final status before marking it failed or retrying.

Reconcile every day

Your ledger is only correct if it matches the outside world. Reconciliation compares your records with external sources, usually settlement reports from payment gateways and bank statements:

  1. Import the external report automatically each day.
  2. Match each external line to your transactions by reference ID, amount and date.
  3. Flag anything that doesn't match: missing on either side, different amounts, unexpected fees.
  4. Route exceptions to a person with a clear queue and a resolution workflow.

A small number of exceptions is normal. What matters is that every one is found within a day and resolved with a recorded reason, rather than discovered months later.

Build the audit trail in

For every transaction, record who or what initiated it, when, from which system, and with which idempotency key and external reference. Restrict who can post manual adjustments, require a reason, and consider requiring a second person to approve them. These records make audits and customer disputes far quicker to answer.

Test what matters

  • Property-based tests that assert every transaction balances and no account goes below its allowed minimum.
  • Concurrency tests that fire simultaneous debits at one account.
  • Replay tests that send duplicate and out-of-order webhooks.
  • A daily check in production that recomputes balances from entries.

Summary

Integer amounts, double-entry transactions, an append-only history, idempotency everywhere and daily reconciliation. None of these are complicated on their own, but they need to be designed in from the start. Adding them to a live product with inconsistent data is much harder.

We build payment, wallet and back-office systems for FinTech and e-commerce companies, with quality engineering built into delivery. If you're designing a ledger or untangling one, we'd be glad to help.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call