Customer work

Enterprise Data Quality and Reconciliation Engine

Dual-implementation proof — an independent Python oracle diffed against production SQL — embedded in two delivered pipelines.

Embedded in two pipelines — each in validation/UAT
Business context

Two of our delivered data engines — a finance management-information-system (MIS) rebuild and an inventory reconciliation build, both for manufacturers, both on SQL Server — needed the same thing underneath the business logic: proof that a calculation is correct before anyone downstream has to trust it blind. That proof mechanism is its own piece of engineering, reused across both builds rather than written twice, and is the subject of this page.

The operational problem

A calculation engine that replaces a spreadsheet inherits the spreadsheet's real risk: a wrong number that looks right. SQL can compute a plausible-looking total from a logic error just as easily as a correct one, and a single code review does not catch every case — especially under the volume and edge-case density of real month-end data across hundreds of thousands of formula-equivalents.

Why existing processes are insufficient

Code review and unit tests check that code does what the author intended; neither checks that the author's intention matches the actual business rule reliably at scale. A single implementation, however carefully reviewed, has no independent witness. And once a schema evolves — tables added, columns renamed, retention runs applied — there has to be a way to prove nothing was silently lost or duplicated in the process.

Proposed solution

A reconciliation engine built on three independent layers of proof: a layered schema with versioned migrations so every structural change is reviewable; a Python-written oracle for each calculation that matters, built independently from the same business rules and diffed against the SQL engine's own output; and hash-verified lineage so every row's journey from staging to final output can be checked, not just assumed.

Solution architecture

                         ┌───────────────────────────┐
                         │  Layered schema             │
                         │  (ctl / ref / stg / core /   │
                         │   calc / rpt)                │
                         │  15-18 versioned migrations  │
                         └──────────────┬────────────┘
                                         │
                    ┌────────────────────┼────────────────────┐
                    ▼                                          ▼
         ┌────────────────────┐                   ┌────────────────────┐
         │  SQL Server          │                   │  Python oracle       │
         │  calculation engine   │  ── diff ──────▶  │  independent         │
         │  (production logic)   │                   │  re-implementation   │
         └────────────────────┘                   └────────────────────┘
                    │
                    ▼
         ┌────────────────────┐
         │  Hash-verified         │
         │  lineage: every row     │
         │  traceable staging →    │
         │  core → output          │
         └────────────────────┘
                    │
                    ▼
         ┌────────────────────┐
         │  Run ledger            │
         │  (ctl schema): every    │
         │  run, retention action, │
         │  protected run_id        │
         │  logged                 │
         └────────────────────┘
  1. Step 1
    Layered schema, versioned migrations
  2. Step 2
    SQL Server engine
  3. Step 3
    Python independent oracle
  4. Step 4
    Diff
  5. Step 5
    Hash-verified lineage
  6. Step 6
    Run ledger (ctl)
Data and application integrations

Input: staged transactional data from each host pipeline (in our two deliveries: SAP export-derived finance and inventory data) — the engine is schema-aware, not source-specific. Internal: the SQL Server calculation engine and its Python oracle run against the same staged input independently; a diff step compares their outputs row by row. Governance: a run ledger in the ctl schema records every pipeline run and every retention or cleanup action taken against staging, with protected run_ids that a retention process must not touch.

Technology stack
  • SQL Server (calculation engine, layered schema)
  • Python (independent oracle — a separate reimplementation, not a thin SQL wrapper)
  • Versioned SQL migrations
  • Hash-based row verification for lineage
End-to-end workflow
  1. 1
    Stage

    Transactional data stages into the layered schema (stg), hash-recorded on arrival.

  2. 2
    Compute (SQL)

    The SQL Server engine computes the business-rule output for the run.

  3. 3
    Compute (oracle)

    Independently, the Python oracle computes the same output from its own implementation of the same rules.

  4. 4
    Diff

    The two outputs are diffed; any mismatch is logged as an open discrepancy, not silently resolved either way.

  5. 5
    Verify lineage

    Lineage hashes are checked end to end — staging row to core row to final output — to confirm nothing was dropped or duplicated.

  6. 6
    Retain safely

    Retention and cleanup actions against staging run only against run_ids not flagged as protected; protections are enforced by the retention logic itself.

  7. 7
    Log

    Every run, match result, and retention action is written to the run ledger.

Implementation methodology

The oracle is not generated from the SQL, and the SQL is not generated from the oracle — each is written independently from the same documented business rule, specifically so a bug in one implementation's interpretation is unlikely to reproduce itself identically in the other. Where the two disagree, that disagreement is the finding, not a race to decide which one is "right" by assumption. Retention runs against staging are themselves treated as a governed action requiring the same discipline as a schema migration, not a one-off cleanup script.

Security and governance

The run ledger is append-only and lives in the ctl schema, separated from the transactional data it describes, so audit history can't be edited by the same process that produced the data. The engine's one approved retention run to date deleted 2.17 million rows from staging tables that had grown to roughly 1 million rows each across the host pipelines, while protecting 66 run_ids from deletion — those protections are enforced by the retention logic, not by a person remembering which runs matter. That run is the clearest proof on record that this engine has handled production-representative volume, not a demonstration figure.

Deployment considerations

The engine is embedded inside two delivered pipelines rather than offered as a standalone product today: a finance MIS rebuild (validated end to end in a developer replica environment) and an inventory reconciliation build (advanced UAT, Finance sign-off pending). Both run on SQL Server, on-prem or in a client-controlled environment — no cloud dependency in the reconciliation layer itself.

Expected operational benefits

A number that disagrees between two independently written implementations surfaces before it reaches a customer or a Finance reviewer, not after.

A retention run that might otherwise risk deleting the wrong data instead runs against logic-enforced protections.

No defect-catch rate or hours-saved figure is stated — no such measurement exists on record; the retention volumes and dual-implementation method above are what the engine has handled, not a claimed outcome.

What makes this technically challenging

Writing a second, independent implementation of the same business logic is slower than writing it once and testing it — that's the point, and also why most teams skip it. Doing this across hundreds of thousands of formula-equivalents, where the two implementations have to agree not approximately but to the row, meant the oracle had to be built with the same rule-by-rule rigor as the production engine, not as an afterthought cross-check. Designing a retention process that can delete millions of rows safely, with specific run_ids structurally protected rather than manually remembered, is the same problem as the reconciliation itself: proving a destructive action did only what it was supposed to, before and after it runs.

Embedded in two pipelines — each in validation/UAT

Status: Implemented, embedded in two delivered pipelines, each independently in validation or UAT. The engine itself — layered schema, versioned migrations, dual-implementation reconciliation, hash-verified lineage, governed retention — is in active use inside both; it is not offered or deployed as a separable product on its own today. The one approved retention run on record processed roughly 1-million-row staging tables, deleted 2.17 million rows, and protected 66 run_ids; that is what the engine has handled, not a client-facing outcome metric. Finance sign-off on the host pipelines' calculated output is tracked separately in each pipeline's own case study and has not been given as of this page's last update.

Want to talk about something like this?