Skip to content

Data engineering basics · Part 7 of 10

Data quality checks: catch bad data before your users do

Simple automated checks for freshness, uniqueness, nulls and ranges catch most data problems early. Learn what to test and where to run the checks.

· 2 min read

data-engineeringdata-quality

A pipeline that runs successfully can still deliver wrong data. A job that finishes green but loads zero rows is worse than one that fails loudly, because nobody notices until a report looks odd.

The checks that pay off first

  • Freshness: the newest row is not older than expected.
  • Volume: today's row count is within a normal range compared with recent days.
  • Uniqueness: a primary key appears once.
  • Not null: required columns are filled in.
  • Accepted values and ranges: a status is one of a known list, an amount is not negative.
  • Referential integrity: every foreign key finds its parent row.

Write them as queries that return bad rows

A check is a query that returns the offending rows. Zero rows means pass.

SQL
-- duplicate keys
SELECT order_id, count(*) FROM orders GROUP BY order_id HAVING count(*) > 1;

-- null in a required column
SELECT * FROM orders WHERE customer_id IS NULL;

-- impossible values
SELECT * FROM orders WHERE total < 0;

Where to run them

  1. At the boundary, right after loading raw data: did the source send what we expect?
  2. After transformation, before publishing: do the final tables obey the rules?

Run the checks in the same orchestration as the pipeline, so a failure stops downstream tasks instead of publishing bad data.

Decide what failure means

Not every failed check deserves a page at night. Mark some as blocking, which stop the pipeline, and others as warnings that notify the owner. A duplicate primary key is blocking. A row count 15 percent below average may only be a warning.

Avoid alert fatigue

Checks that fail constantly teach people to ignore them. Start with a handful of meaningful tests per important table, tune thresholds from real history, and give every table an owner who receives the message.

Takeaway

Treat data like code: test it automatically, close to where it is produced, and make failures visible and owned. Start small and add a test whenever a real incident teaches you a new rule.

A knowledge article, drafted with AI assistance and checked with automated tests. It is general background, not a description of my own experience or of any client's work.

Comments

Leave a comment

No account or email needed. Comments appear after review. A one-way hash of your IP address is kept for 30 days to fight spam, then erased.