Finance · Reconciliation · SQL engine

Transaction Reconciliation Engine

A three-way month-end reconciliation (ERP ledger ↔ payment gateway ↔ bank) in DuckDB SQL that explains every rupee of a ₹15.41 L gap, validates itself against ground truth and tells finance what each exception is worth.

Solo project · end to endNov 2026

The problem

A mid-size Indian D2C retailer takes nearly all its revenue through a payment gateway. Every month end, finance has to prove that each sale was paid, that the gateway paid what it owed after its contracted fees, refunds and chargebacks, and that the money reached the bank. It was done by hand in Excel over ~25,000 rows, took three to four days and still ended with an unexplained difference that got written off.

The data

Four reproducible exports from a seeded generator with documented assumptions: an ERP ledger (24,261 rows, IST, three date formats, text amounts), a gateway transaction report (24,298 rows, UTC, amounts in paise, messy order refs), 32 daily payouts and the October bank statement. Twelve kinds of real reconciliation problems are injected and labelled, so the engine can be scored; the engine never reads the labels.

Approach

  1. Logged cleaning pipeline

    18 rules, each logging the rows it touched; removed rows go to a quarantine table with a reason; 19 validation checks (unique keys, GST = 18% of fee, payout arithmetic, bank balance recomputes) must pass.

  2. EDA

    A plain order-id join gets 97.7%. The rest splits into an IST/UTC cut-off artefact (112 rows), one-directional checkout discounts, fees above contract, unbooked refunds and a held payout.

  3. SQL engine in DuckDB

    A 9-rule cascade with FULL OUTER JOIN and ordered CASE, a per-transaction fee audit with LAG() to find rate changes, many-to-one payout rebuilds, a 619-item exception register with owners, and a cash bridge from ERP sales to bank credits.

  4. Validation against ground truth

    Precision and recall per exception type with Wilson intervals, error analysis that found and fixed two engine bugs, rule-sensitivity sweeps, and the frozen rules rerun on 20 newly generated months.

  5. Dashboard

    Four Power BI-style pages on six SQL marts, published only after 7 tie-out checks against the engine pass.

  6. ₹ impact and recommendations

    Cash to recover, revenue misstatement tested against materiality, and annual cost at current rates with bootstrap intervals over 20 months; 8 ranked actions with owners.

What I found

What the exceptions are worth (October)
SectionLine₹
Recover nowSettlement held by the gateway (19 Oct)₹6,41,741.68
Recover nowFee overcharge claim₹3,953.16
Books wrong if closed nowNet revenue overstatement₹2,28,750.50 (1.04%)
Recurring costFee overcharge at current rates, incl. GST₹81,299 / year
Revenue at risk (not a cost)Receipts with no captured payment₹1,61,250 / month

Charts

Cash bridge: ERP net sales to bank credits, ₹0.00 unexplained
Cash bridge: ERP net sales to bank credits, ₹0.00 unexplained
What the exceptions are worth: cash to recover, revenue misstatement, recurring cost
What the exceptions are worth: cash to recover, revenue misstatement, recurring cost
Engine scored against ground truth, per exception type
Engine scored against ground truth, per exception type
Exceptions page: owner work queue with slicers and export
Exceptions page: owner work queue with slicers and export

Live dashboard

Interactive: filter by segment and hover any chart. Open full screen ↗

The key insight

A clean bridge doesn't prove the classification is right, so the engine was scored against labelled ground truth: 0 false positives and 2,073 of 2,075 in-scope problems caught. Scoring found two real bugs (31 Oct refunds and a 31 Oct/1 Nov booking) that a ₹0.00 bridge had hidden. For the controller, the result is a short, owned work list: recover the held ₹6.42 L payout, post receipts from the payment-capture event, and get the wallet rate back to contract.

Limitations & next steps

Tools