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.
-- 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
- At the boundary, right after loading raw data: did the source send what we expect?
- 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.
Comments