An Apache Spark-based analytics platform optimized for Azure.
In Azure Databricks, when the same source feeds landing, reference, and transformation (trans) layers, you should establish a single, authoritative ingestion point. Load the source into the landing/raw layer first, capture the ingestion timestamp, batch/run ID, source record count, and checksum or other reconciliation metadata. Downstream reference and transformation processes should consume that controlled landing data rather than independently extracting from the source.
For the mismatch-count issue, implement record-count reconciliation at every stage: source → landing, landing → reference, and landing → trans. Store expected and actual counts, rejected/error counts, duplicate counts, and processed counts in an audit/control table. A pipeline should flag or fail when counts do not reconcile according to explicitly defined rules, rather than silently continuing.
Use Delta tables with ACID transactions, idempotent processing, and a consistent business key. Avoid relying solely on COUNT(*); also reconcile key fields, aggregates, and, where appropriate, hashes. Handle late-arriving data, deletes, duplicates, and retries explicitly. Each pipeline run should have a unique batch/run ID so records can be traced from the original source through every downstream layer.
The preferred pattern is essentially Source → Landing/Raw → Reference and Trans → Curated/Serving, with centralized audit/reconciliation between each layer. This prevents multiple independent reads of the source from producing different snapshots and makes a count mismatch much easier to isolate.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin