No. 50Backend9 min read2,266 words
Payment reconciliation for fintech: ledgers that balance
Payment reconciliation for fintech apps: double-entry ledger design, idempotent webhooks, a daily reconciliation job and the failure cases that lose money.
- Written by
- Lazy Devs
- Published
- Updated
- Sources
- Cited inline

Key takeaways · 05
The short version
- 01Payment reconciliation is the daily process of matching every entry in your own ledger against your payment provider's and bank's records, and explaining every difference.
- 02Use an append-only double-entry ledger: every movement is a set of debit and credit entries that net to zero per currency, and balances are derived by summing entries, never stored as an editable field.
- 03Record the webhook event ID and the resulting ledger entries in the same database transaction, so a crash cannot mark an event as handled without posting it.
- 04Model the provider as its own clearing account, with money moving from pending to settled to paid out, and match on the provider's transaction ID rather than amounts.
- 05Correct mistakes with new adjusting entries, never edits or deletes, and alert loudly on any break the reconciliation job cannot explain.
On this page · 11
Payment reconciliation is the discipline of making sure your records and your payment provider's records agree, every day, down to the smallest currency unit, and being able to explain every difference. In a fintech app it rests on three things: an append-only double-entry ledger as your internal source of truth, idempotent handling of every provider event, and a scheduled job that matches your ledger against the provider's reports and alerts on anything it cannot explain.
Picture month-end. Your dashboard shows one total, your provider's dashboard shows a slightly different one, and nobody can say whether the gap is money that went missing or money that never existed. The number may have been wrong for weeks, invisible because nothing was watching. Reconciliation is what stops that from happening. It never demos well, and it is the thing that separates a fintech product you can trust from one that quietly loses money.
This post goes deeper than our guide on how to build a fintech app, for the founder or engineering lead who must never lose track of money.
This is engineering guidance, not accounting, legal or regulatory advice. Agree your ledger design and close process with your accountant and, if you have one, your partner bank.
What you are actually reconciling
There are usually three books, not two:
| Book | What it records | Typical identifier |
|---|---|---|
| Your internal ledger | What your product believes happened: charges, transfers, fees, refunds | Your transaction ID plus the provider's ID |
| Your payment provider | What the processor or BaaS partner actually did, and when funds settled | The provider's charge, transfer and balance transaction IDs |
| Your bank account | What actually arrived or left as payouts | Payout ID and bank reference |
Reconciliation runs at two levels. Transaction-level matching pairs each ledger entry with the provider's record. Payout-level matching confirms that each payout landing in your bank equals the sum of the transactions the provider says it contains. Stripe, for example, publishes a payout reconciliation report for exactly this purpose; other providers have equivalents.
A ledger is not a balance column
The first mistake is storing a balance as a number you update. A user deposits, you add. They withdraw, you subtract. The moment two requests touch that row at once, or a crash lands between the read and the write, the number is wrong and you have no way to prove what it should have been.
The fix is centuries old: double-entry bookkeeping. You never overwrite a balance. You record immutable entries, and every movement of money is a set of entries that net to zero per currency. Money leaves one account (a debit) and arrives in another (a credit), in the same database transaction. The balance of any account is the sum of its entries.
That symmetry is the point. If every transaction nets to zero, the whole ledger nets to zero, and the day it stops doing so you have found a bug in seconds instead of at audit. The append-only history also means any balance is traceable: you can replay exactly how an account reached its current state. PostgreSQL is the natural home for this, for the reasons in why we reach for Postgres first: real transactions, constraints and exact integer types.
Enforce the invariant in the one function allowed to write entries:
type Leg = {
accountId: bigint;
direction: "debit" | "credit";
amount: bigint; // minor units, always positive
currency: string; // ISO 4217
};
async function postTransaction(tx: Tx, txnId: string, legs: Leg[]) {
const net = new Map<string, bigint>();
for (const leg of legs) {
if (leg.amount <= 0n) throw new Error("Amounts must be positive");
const signed = leg.direction === "debit" ? leg.amount : -leg.amount;
net.set(leg.currency, (net.get(leg.currency) ?? 0n) + signed);
}
for (const [currency, total] of net) {
if (total !== 0n) throw new Error(`Unbalanced ${currency} in ${txnId}`);
}
await tx.ledgerEntries.insertMany(legs.map((leg) => ({ ...leg, txnId })));
}And check it continuously in the database, so a bug elsewhere cannot hide:
-- Any row returned is a bug. Run it in CI against fixtures and on a schedule in production.
select txn_id, currency,
sum(case when direction = 'debit' then amount else -amount end) as net
from ledger_entries
group by txn_id, currency
having sum(case when direction = 'debit' then amount else -amount end) <> 0;Design accounts that mirror reality
The conceptual leap most teams miss: your ledger and the provider's ledger are separate sources of truth that will drift for perfectly honest reasons. The way to keep them reconcilable is to model the provider inside your own ledger.
| Ledger account | What it represents |
|---|---|
| Customer accounts | What you owe each customer |
| Provider pending | Charges the provider has accepted but not yet settled |
| Provider available | Settled funds sitting at the provider |
| Bank (operating) | Money that has actually arrived in your bank |
| Processing fees | Fees the provider deducts |
| Refunds and disputes | Money returned or held back |
| Suspense | Unexplained items awaiting investigation; should trend to zero |
A card charge then becomes a sequence of balanced transactions, each matched by the provider's own IDs: the charge moves money into provider pending; settlement moves it to provider available and books the fee; the payout moves it to the bank account. Anything stuck in pending too long, or present at the provider but missing from your ledger, is an exception a human looks at. The suspense account gives unexplained items somewhere honest to live while that happens, instead of being forced into the wrong place.
Idempotency: the gate that stops double-counting
Webhooks are how the provider tells you what happened, and webhooks are unreliable by design. Stripe's webhook documentation is explicit that endpoints can receive the same event more than once and that delivery order is not guaranteed. If your handler posts ledger entries every time a webhook lands, one retried success event books the money twice.
Every event needs an idempotency gate, and it must commit together with the ledger write:
async function handleProviderEvent(event: ProviderEvent) {
await db.transaction(async (tx) => {
// INSERT ... ON CONFLICT DO NOTHING on a unique event_id column.
const isNew = await tx.processedEvents.insertIfAbsent(event.id);
if (!isNew) return; // already handled
const legs = mapEventToLegs(event); // pure function, easy to test
await postTransaction(tx, event.id, legs);
});
}If you record the event ID and then crash before writing the entries in a separate transaction, you have marked the event handled without handling it, and the retry will skip it forever. One transaction removes that failure mode. Postgres's INSERT ... ON CONFLICT makes the gate safe under concurrency too: a simultaneous duplicate waits for the first insert to commit, then does nothing. Our field guide to webhooks done right covers signature verification, retries and queueing in more depth.
The failure cases most teams skip
A demo handles the happy path. Real money lives in the unhappy ones.
- Out-of-order events. A refund event arrives before the charge it reverses. If your handler assumes the charge exists, it throws, the webhook fails, and the refund may never book. Record what you know, fetch the current state from the provider's API if needed, and never assume ordering.
- Partial failures across systems. Inside one database transaction, both legs commit or neither does. The danger is a call to the provider's API in the middle of your flow. Use a pending state before the call and let the provider's event or reconciliation confirm the outcome, rather than attempting a distributed transaction.
- The duplicate that is not a duplicate. A customer legitimately buys the same thing twice in one second. Deduplicating on amount and account collapses two real charges into one. Idempotency keys must come from the operation, not from guessing based on data.
- Races on balances. A balance check and a withdrawal that race can push an account negative. Take a row lock on the account (PostgreSQL's explicit locking with
SELECT ... FOR UPDATE) or use a constraint, not anifstatement two requests can both pass. - Fees, disputes and currency conversion. These arrive as separate provider records with their own timing. If your ledger only models charges and refunds, every fee and dispute shows up as a break.
- Partial refunds and partial captures. One charge, several later movements. Model them as separate transactions linked to the original.
Reconciliation is a job, not a vibe
Knowing reconciliation matters is not the same as running it. The mechanism is a scheduled job, at least daily and more often as volume grows:
- Pull the provider's records for the period: balance transactions, payouts, fees, disputes.
- Normalise them into the same shape as your ledger entries: amounts in minor units, currency, provider IDs, timestamps in UTC.
- Match by provider ID, never by amount alone.
- Classify every unmatched item into a known break type.
- Alert on anything unexplained, with enough context to investigate.
- Resolve with adjusting entries, never by editing or deleting history.
| Break type | Likely cause | Action |
|---|---|---|
| In provider, missing in ledger | Lost or failed webhook | Replay the event or fetch from the API; post the missing entries |
| In ledger, missing at provider | Call failed after you recorded pending, or a bug | Check provider status; reverse the pending entries if it never happened |
| Amount mismatch | Fee, partial refund or currency conversion not modelled | Post the missing fee or adjustment; fix the mapping |
| Stuck in pending | Delayed settlement or a missed event | Query the provider; escalate past your threshold |
| Payout total mismatch | Missing transactions inside the payout | Reconcile the payout's line items one by one |
The point worth repeating: nobody watches background jobs on a Tuesday night, which is exactly why they fail there. A reconciliation job that runs silently is worse than none, because it gives false confidence. Run it on durable infrastructure with retries, as described in background jobs and queues for web apps, make it loud when it finds a break, and give the team a daily summary they actually read.
Cut-offs, time zones and settlement dates
A surprising number of reconciliation breaks are not errors at all. They are two systems drawing the line between days in different places. Your ledger may close the day at midnight UTC, your provider's reports may use a different time zone or report by settlement date, and your bank may book a payout on the next business day. Compare those naively and every day near midnight looks broken.
A few rules keep timing from drowning out real problems:
- Store every timestamp in UTC, and keep both the time the event happened and the time you recorded it. They differ whenever a webhook is delayed or replayed.
- Pick one cut-off and document it. Reconcile a closed period, such as yesterday in UTC, rather than a moving window, so the job gives the same answer when it is rerun.
- Match on the date the provider uses. Most providers distinguish when a charge was created from when its funds became available. Stripe's balance transactions, for example, carry an
available_ondate. Use the field that matches the account you are reconciling. - Let late items roll forward explicitly. An item created on Monday that settles on Wednesday should appear as an expected, aged timing difference until it clears, not as a break every day in between.
- Treat weekends and bank holidays as data. Payouts do not arrive on days the banking system is closed. A calendar of non-business days stops your job from alerting every Saturday.
Once timing differences are classified and aged, anything left over is far more likely to be a genuine problem, and the alerts people receive are ones they will actually read.
The audit trail that makes it defensible
When something is off, you need to answer "who did what, to which account, when and why" months later, including actions by your own staff and support tools. In fintech, that is a product requirement and often a partner or regulatory one, not a debug log.
Keep the audit trail append-only, timestamped and separate from the operational data it describes. The ledger tells the money story; the audit trail tells the human story around it: who approved a manual adjustment, who resolved a break, which support agent issued a refund. Together they turn "we think it was a glitch" into "here is exactly what happened". Retrofitting either means reconstructing history you no longer have.
Build or buy the ledger?
A PostgreSQL ledger like the one above is well within reach for a capable team, keeps your core data model under your control, and is what we usually recommend for early-stage products with straightforward money flows. Ledger-as-a-service products can make sense for complex, multi-party flows or very high volume. That is a genuine build versus buy decision worth making deliberately. Either way, reconciliation against your provider and bank is still your job.
Get the money plumbing right
Store money in an append-only double-entry ledger, never a balance column. Model the provider as accounts in that ledger. Make every webhook handler idempotent, with the event ID and the ledger write in one transaction. Reconcile daily against the provider's records, match on IDs, and alert on every break you cannot explain. Test the unhappy paths, because that is where real money goes missing. For the wider set of compliance and architecture decisions around this, see web app considerations for fintech, and for the onboarding side, KYC and identity verification.
This is squarely the work we do for fintech teams, and the work we get called in to untangle when the numbers stop matching. If you want a second pair of eyes on your ledger and reconciliation before a mismatch finds you, tell us what you are building.
FAQ · 05 questions
Frequently asked questions
What is payment reconciliation?
Payment reconciliation is the process of comparing your internal record of payments with your payment processor's and bank's records, and resolving any differences. In a fintech product it runs automatically, at least daily, matching individual transactions, fees, refunds, disputes and payouts down to the smallest currency unit.
What is a double-entry ledger in software?
A double-entry ledger records every movement of money as at least two immutable entries, a debit to one account and a credit to another, that sum to zero. Account balances are calculated from the entries rather than stored and edited directly, which gives you a complete, auditable history and an invariant that exposes bugs.
How often should a fintech app reconcile payments?
At least daily, and more often once volume grows. Many teams also reconcile each payout when it arrives at the bank. The key is that the reconciliation job alerts on any difference it cannot explain, because a silent job gives false confidence.
Should I build my own ledger or use a ledger service?
Both are reasonable. A ledger on PostgreSQL is well within reach for a competent team and keeps your core data model under your control. A ledger-as-a-service product can save time if your money flows are complex or high volume. Either way, you still need reconciliation against your payment provider and bank.
Why do my balances not match Stripe?
Usually because of timing and things you have not recorded yet: funds still pending before settlement, processing fees, refunds and disputes that arrived by webhook late or not at all, currency conversion, or payouts in transit. A reconciliation job that matches on the provider's transaction IDs will separate these expected timing differences from genuine errors.