What is reconciliation and how do you test it?
Reconciliation compares our operations with provider or bank data by a shared key to find differences in operations, amounts, statuses and duplicates. It is needed because data in a distributed system does not match instantly. Tests check each difference lands in one class and the total gap is fully explained by exceptions, plus a repeated run, the day boundary with a waiting window, and duplicates.
QA Fundamentals · Fintech specifics
We have 1,000 payments, the bank has 998. Where are the two?
At the end of the day a finance person compares the payment register in the system with a bank statement or a payment provider's file. The totals should match, but they do not: one system has operations that the other lacks, somewhere an amount differs, somewhere the same operation appears twice. If nobody knows about a difference, the money is simply lost, and a month later it is searched for among thousands of rows. This lesson is about what reconciliation is, why differences appear even without "bad" code and what exactly QA tests.
How it works and why. Reconciliation is a comparison of two (sometimes three) sources of truth about the same operations: our system, the provider, the bank. It is needed because the system is distributed: a payment goes through several parties, requests get lost, webhooks arrive late, the provider groups settlements into batches and deducts a fee. Even when everyone works correctly, the data does not match instantly. So reconciliation is run regularly (daily or more often), instead of hoping it will never diverge.
The mechanism is simple. Take the provider's file or API statement, match each row with our record by a shared key (usually a reference or the provider's transaction id), then compare the amount, currency, status and date. The result is sorted into classes, and each has its own route:
How reconciliation sorts operations
The reasons for differences are usually these: an operation is only ours (a timeout, the provider did not process it, the request did not arrive), only the provider's (we did not get a webhook, a write error), a different amount (a fee, rounding, an input error), a different status (we have "captured", the bank has "refunded"), a duplicate (a repeated file delivery, a repeated payment). So not only the match is tested but each of these classes.
Example: from files to a report. There is the data of our system and a provider file for a day:
Our system Provider file
ref amount status ref amount status
ord-1001 100.00 captured ord-1001 100.00 captured
ord-1002 50.00 captured ord-1002 50.00 captured
ord-1003 75.50 captured ord-1003 75.05 captured
ord-1004 20.00 captured (missing)
ord-1005 100.00 captured ord-1005 100.00 captured
ord-1005 100.00 captured
(missing) ord-1006 30.00 captured
Total: 345.50 Total: 455.05
On the surface the difference is 109.55, but reconciliation breaks it down into concrete rows. The expected report:
Matched: ord-1001, ord-1002
Different amount: ord-1003 (75.50 ours, 75.05 provider, -0.45)
Only ours: ord-1004 (20.00, -20.00)
Only in provider: ord-1006 (30.00, +30.00)
Duplicate in file: ord-1005 (extra +100.00)
Sum check: 30.00 + 100.00 - 20.00 - 0.45 = 109.55 = 455.05 - 345.50
The last line is important: the difference in the total must be fully explained by the list of exceptions. If after all the explanations a kopeck is left, reconciliation is missing something. This is a good automatic invariant for a test. This example also shows different types of errors: 75.50 against 75.05 is a swap of digits (a write or input error), ord-1004 could have been lost to a timeout, and ord-1005 is a duplicate in the file that should not be counted twice.
It is useful for QA to know how to run this check by hand. The query below finds unmatched rows and different amounts (status and currency are added to the WHERE the same way), but not duplicates, because a duplicate in the file is matched with the same row of ours and the amount is the same in both copies. So duplicates are caught by a separate query:
SELECT COALESCE(o.ref, p.ref) AS ref, o.amount AS ours, p.amount AS provider
FROM our_payments o
FULL OUTER JOIN provider_rows p ON p.ref = o.ref
WHERE o.ref IS NULL OR p.ref IS NULL OR o.amount <> p.amount;
-- duplicates are NOT visible above: both copies match the same row
SELECT ref, COUNT(*) FROM provider_rows GROUP BY ref HAVING COUNT(*) > 1;
If the DBMS does not support FULL JOIN (MySQL does not have it), two LEFT JOINs are combined with UNION instead.
What is tested in reconciliation itself, besides sorting into classes:
- A repeated run: a second reconciliation of the same data does not create duplicates in the exceptions queue and does not "close" old ones.
- The day boundary: an operation at 23:59 on our side and at 00:01 at the provider (another time zone or a delay) must not become a permanent exception. There is a waiting window for those.
- Aggregation: one provider payout consists of many payments minus a fee. Reconciliation sums the batch and compares it with the payout, rather than finding "extras".
- Files: an empty file, a header only, another encoding, a corrupted row, a large volume, unusual characters in fields.
- An exception's life: it goes into a queue, has an owner, a status and an age; a resolved exception does not return.
- Permissions: who can close an exception or make a correcting entry, and whether a trace remains in the audit log.
Limits and alternatives. For money the tolerance is normally zero: "roughly matches" is unacceptable, and only known differences (a fee) are explained by a rule. For time there is a tolerance: a payment late in the evening can land in the next day's file, and reconciliation must know it. There is two-sided reconciliation (we and the provider) and three-sided (a bank statement too), and also real-time reconciliation against a batch daily one. Automatic reconciliation does not remove the manual one: some exceptions need a human, for example whether to write to the customer or refund. There is also an internal version: differences between our balance and the sum of all entries in the ledger (internal reconciliation), which is tested the same way, at the invariant level.
Common mistakes.
- Checking only a perfect match: the most valuable thing reconciliation does is find differences.
- Ignoring duplicates and empty data: "found everything" really means a file with a repeat was not checked.
- Checking only the amount and not the status: a payment can match by money while we have "captured" and the bank has "refunded".
- Not checking a repeated run: a second pass breeds copies or wipes out the previous review.
- Taking test files with clean data only: real files have another encoding, extra spaces, total rows.
- Treating "a difference of one kopeck" as a trifle: such a difference is most often a sign of rounding.
Check yourself
A FULL OUTER JOIN query by ref shows zero differences, but the totals of our payments and the provider file differ by 100.00. What do you check?
Answer
Duplicates: if a provider row repeats twice, both copies match the same row of ours and the amount is identical. Check GROUP BY ref HAVING COUNT(*) > 1 in the provider file. There can also be rows with a different currency or status that a query by amount does not show.
An operation at 23:59:30 is in our register, but the provider file for that day lacks it, while it is in the file of the following day. Is it a difference or not, and how do you reflect it in a test?
Answer
It is an expected delay, not an error, if it fits the window set by the requirement. Reconciliation must neither close it as a match nor escalate it at once as a loss, but hold it in a waiting state. The test: an operation on the day boundary appears among exceptions only after the window ends and disappears when it arrives in the next file.