Silent wrong data: four faults every pipeline should survive
The worst pipeline failure gives no error. The job runs, the dashboard loads, and the numbers are wrong.
Two recent write-ups show this. In one, an engineer built a test ERP that changes during the read. The author then measured a typical incremental extractor against it. "It was 30.8% wrong. It never threw an error. Not one." (Tim Collinson, dev.to). In the other, a team that queries about 1 billion rows of Brazilian public-safety data states its first rule: "the last month in the file is always incomplete" (Crime Brasil, dev.to).
This note covers four faults that pass every check that looks only for crashes. For each fault, it gives what the fault is, how to detect it, a test to add, and a fix. The SQL is standard and runs in DuckDB and Postgres. Change the table names to match your schema.
1. Late-arriving rows
What. Rows for a past period arrive after you closed that period. The newest period is too low at first, then it grows. The Crime Brasil post shows the São Paulo feed falling from 2,459 reports on 2026-08-26 to 994 on 2026-08-31. A normal day there is 2,400 to 2,900 reports. A month-on-month comparison then shows a drop in crime that is only a drop in paperwork.
Detect. Store the row count for each period after each load. A closed period must not change. If an old period still grows, you have late data.
SELECT period,
min(row_count) AS first_count,
max(row_count) AS last_count
FROM load_counts
GROUP BY period
HAVING min(row_count) <> max(row_count)
ORDER BY period;
Test. Load a batch. Then load a second batch that has rows dated in the first period. The totals must match a full reload.
Fix. Re-process a trailing window on each run, for example the last N days. Key on the event date and merge, do not append. Show the window in reports, and do not report the newest period until its counts are stable.
2. Duplicate change-capture (CDC) rows
What. The same change arrives twice after a retry or a replay. Sums double, and nothing fails.
Detect. Count rows for each primary key and change sequence number. A count above 1 is a duplicate.
SELECT order_id, change_seq, count(*) AS copies
FROM orders_cdc
GROUP BY order_id, change_seq
HAVING count(*) > 1;
Test. Replay the same CDC batch twice. The target table must not change on the second load.
Fix. Use an idempotent merge keyed on (primary key, sequence number). Do not use plain inserts. Deduplicate the staging table before the merge, because one batch can hold the same change twice.
3. Reverted or reorged rows
What. The source removes or replaces a record that you already loaded. In a business system, this is a voided invoice or a cancelled order. In the ERP test above, the incremental extractor kept 55 rows that the ERP had deleted. On a blockchain, this is a reorg. Reorgs, finality and idempotency covers the chain case in full.
Detect. Store the source's own version, or the block hash, with each row. After the finality window, read the source again. Find loaded rows that the source no longer has at that version.
SELECT t.invoice_id, t.version
FROM invoices AS t
LEFT JOIN source_invoices AS s
ON s.invoice_id = t.invoice_id
AND s.version = t.version
WHERE s.invoice_id IS NULL;
Test. Load a range. Then load a replacement for the last part of that range. Only the replacement rows must stay.
Fix. Hold data as provisional until it is final, or delete and re-insert by range. An incremental read by timestamp does not see deletes. Do a scheduled full read of the keys, and compare it with the table. Do not delete rows from a full read unless the read is complete. The ERP post describes a sweep that ended early with a clean 200, where the merge "would have deleted everything it missed".
4. Schema drift
What. Upstream renames, retypes or drops a column. The loader fills NULLs or casts the value without a warning. A related fault is a change-tracking column that does not move. In the ERP test, almost all of the 30.8% came from one cause. A nightly labor batch changed quantities but did not update LastModified, so the incremental read never saw the change.
Detect. Compare the incoming schema with a stored contract on every run. Track the NULL rate for each column, and alert when it moves.
SELECT k.column_name,
k.data_type AS expected,
c.data_type AS actual
FROM schema_contract AS k
LEFT JOIN information_schema.columns AS c
ON c.table_name = 'staged_orders'
AND c.column_name = k.column_name
WHERE c.data_type IS NULL
OR c.data_type <> k.data_type;
A row with actual set to NULL is a missing or renamed column. A row with two different types is a retyped column. Type names differ between engines, so write the contract in the names that your engine reports.
Test. Load a batch with one renamed column. The run must stop or quarantine the batch. It must not write NULLs.
Fix. Use a data contract with a stop-or-quarantine rule. Do not cast a type without an alert. Do not trust a source timestamp to find all changes. Compare a full read with the table on a schedule.
The checklist
| Fault | One check | Where it runs |
|---|---|---|
| Late rows | Period counts are stable over loads | After each load |
| Duplicate CDC | One row per (key, sequence) | Merge step |
| Reorg or revert | Version or hash re-check after finality | Scheduled |
| Schema drift | Schema against contract, NULL rate per column | Before the load |
Each check is one query. Each test needs a small synthetic batch that you build once and keep in CI.
What to take away
- A green run tells you that the job finished. It does not tell you that the data is correct.
- Do not report a period until its counts stop changing.
- Key merges on (key, sequence) so that a replay does not change the table.
- Store the source version, and re-check it after the finality window.
- Compare each batch with a schema contract before you load it.
- Build each fault into a test on purpose. Do not wait for production to find it.
Data platform engineering describes how I build pipelines with these checks from the start.
I can check your pipelines for these four faults. You get a list of the faults that each pipeline can hit, the queries that detect them, and the tests and fixes for each one.