Part 07 / Topic 4 of 6
Reconciliation
"The load succeeded" means the process exited zero. Before telling the customer the data is right, reconcile — compare source and target and account for every difference:
# examples/02_reconcile_source_and_target_before_telling.py
import sqlite3
source = {"S-2001": "delivered", "S-2002": "delivered", "S-2003": "delayed", "S-2004": "in_transit"}
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE shipments (id TEXT PRIMARY KEY, status TEXT)")
db.executemany("INSERT INTO shipments VALUES (?, ?)",
[("S-2001", "delivered"), ("S-2002", "in_transit"), ("S-2003", "delayed")])
target = dict(db.execute("SELECT id, status FROM shipments"))
missing = sorted(source.keys() - target.keys())
extra = sorted(target.keys() - source.keys())
mismatched = sorted(k for k in source.keys() & target.keys() if source[k] != target[k])
print(f"source {len(source)} rows, target {len(target)} rows")
print("missing in target:", missing)
print("unexpected in target:", extra)
print("status mismatches:", mismatched)
# source 4 rows, target 3 rows
# missing in target: ['S-2004']
# unexpected in target: []
# status mismatches: ['S-2002']
Four checks, always the same: counts, missing, extra, mismatched. Here reconciliation caught a shipment that never arrived (S-2004) and one whose status diverged (S-2002) — exactly the two failures a "successful" load hides. Run reconciliation after every backfill and on a schedule afterwards; it is the difference between "it worked" and "I checked".
🧪 Quick quiz
- What does reconciliation check?
Show the answer
That source and target agree: counts, missing rows, extra rows and mismatched values. In the example it found S-2004 missing and S-2002 with a different status. (verified against the example output above)
Done here? The practice set for Part 7 — 4 exercises with solutions — is on the part page.