System Design · medium

How do you ensure data quality in a pipeline?

Asked in Analytics Engineer interviews, in the System Design round.

Short answer

Schema tests, freshness/volume checks, anomaly detection, contracts, alerting (e.g., dbt tests).

How to answer it

The principle

Test the data, not just the code. Code tests tell you the transformation is what you wrote; data tests tell you the input was what you assumed. Pipelines almost always break on the second.

Where checks go

At ingestion      schema conformance, required fields, type coercion
                  reject or quarantine, do not silently coerce

After transform   row counts within expected bounds
                  uniqueness on the primary key
                  referential integrity against dimensions
                  accepted values for enums
                  freshness: is the newest row recent enough

Before publish    reconciliation against a source of truth
                  totals match the finance system, or the run does not ship

The four questions every table should answer

Those four cover most incidents, and dbt tests or Great Expectations express them in a few lines each.

Fail loudly, and in the right place

A quality check that logs a warning nobody reads is not a check. Decide per table whether a failure blocks publication or raises an alert while the stale data stays visible. Blocking is right for finance; for a marketing dashboard, yesterday's numbers may beat none.

Anomaly detection on the metrics themselves catches what schema tests cannot: a column that is still perfectly valid and has silently halved.

Key points

FAQ

The 30-second answer

The principle is to test the data, not just the code, because pipelines mostly break on inputs that stopped matching what you assumed rather than on logic you wrote wrongly.
I would put checks at three points. At ingestion, schema and required fields, quarantining bad rows rather than silently coercing them. After transform, the four questions every table should answer: is it fresh, is it complete, is the key unique, are the values valid. And before publishing anything financial, a reconciliation against a source of truth.
The part that gets skipped is deciding what happens on failure. A warning nobody reads is not a control, so per table I would decide whether a failure blocks publication or alerts while the previous data stays up. And I would add anomaly detection on the metrics themselves, because a column can stay perfectly valid while quietly halving.

In the interview

Practice this for real