Data quality monitoring for business data: rules, SQL checks and alerts that reach the right owner

The dimensions that matter for invoices, orders and customer data, how to write data quality rules as SQL, how often to run them, who gets the alert, how to handle failures, and how data contracts and dashboards keep data healthy over time.

Obseria TeamObseria
Summary
  • Data quality monitoring means checking business data automatically and repeatedly against explicit rules: completeness, uniqueness, validity, freshness and volume cover most problems in invoices, orders and customer tables.
  • Every rule boils down to a number compared with a threshold: empty values, duplicates, values out of range or pattern, the age of the newest row, the row count, or a custom SQL query that should return zero.
  • Rules are only useful if failures reach an owner who can act. Give each table an owner, set severity and interval per rule, alert on status changes rather than on every check, and agree data contracts with the teams that run the source systems.

Most broken reports are not caused by wrong formulas. They are caused by data that quietly changed: a sync that stopped three days ago, a CRM export where half the e-mail addresses are empty, an order table where the same order appears twice, or an invoice amount that suddenly arrives in cents instead of euros. The dashboard still shows a number. It is just the wrong one, and nobody notices until a customer or the finance team does.

Data quality monitoring turns these surprises into alerts. Instead of hoping someone spots a strange number, you write down what "correct" means for each table and let rules check it on a schedule. This guide covers the dimensions that matter for business data, how to write data quality rules in SQL, data freshness checks, check intervals, alerting, handling failures, data contracts with source systems and dashboards that show data health.

What is data quality monitoring?

Data quality monitoring is the automatic, repeated checking of data against explicit expectations. It answers three questions continuously: is the data complete, is it correct, and is it current?

It is different from monitoring the systems that move data. When a database is slow or a scheduled job does not start, that is a question for data observability of pipelines and databases. Data quality monitoring looks at the content: the job may have run perfectly and still loaded a file with 2,000 empty customer IDs. You usually want both.

Data quality dimensions for business data

The literature lists many dimensions. For invoices, orders, contacts and tickets, five cover most of what goes wrong in practice:

DimensionQuestionTypical failureRule type
CompletenessAre required fields filled?Contacts without e-mail, orders without customer IDNot null
UniquenessDoes each record appear once?Duplicate invoices after a re-importUnique
ValidityDo values have the right range and format?Negative amounts, VAT IDs in the wrong format, dates in the futureRange, pattern, custom SQL
FreshnessIs the data current enough?Sync stopped, newest row is three days oldFreshness
VolumeIs the amount of data plausible?Table suddenly empty, or ten times bigger than usualRow count, custom SQL

A sixth dimension is worth knowing: consistency asks whether related tables agree, for example whether every order references a customer that exists.

How to write data quality rules

A good rule has four parts: the table and column it checks, a measurement that produces a number, a threshold, and a severity. "E-mail should be filled" is a wish; "the number of contacts without e-mail must be 0, severity warning, checked hourly" is a rule.

The SQL examples below use the dialect of an analytical, ClickHouse-style store. FINAL makes sure you read only the latest version of rows that were updated by key; countIf counts rows that match a condition. In PostgreSQL the same checks use count(*) FILTER (WHERE ...) and the ~ operator for patterns.

Completeness: the not-null rule

Count rows where a required column is empty. For text columns, treat an empty string as missing too, because exports often write "" instead of NULL.

SELECT countIf(email IS NULL OR email = '') AS missing, count() AS total
FROM `contacts` FINAL

Not every column must be 100 % filled. A phone number may be optional; a customer ID on an invoice is not. Decide per column whether the threshold is zero or a tolerated number.

Uniqueness: the unique rule

The difference between all values and distinct values is the number of duplicates. Ignore empty values here; they are a completeness problem.

SELECT count() - uniqExact(invoice_number) AS duplicates
FROM `invoices` FINAL
WHERE invoice_number IS NOT NULL

Uniqueness belongs on every business key: invoice number, order ID, customer number.

Validity: range rules

Numbers that fall below a minimum or above a maximum are suspicious. Typical ranges: amounts not negative, discounts between 0 and 100, quantities below a sensible upper limit.

SELECT countIf(amount < 0 OR amount > 1000000) AS out_of_range
FROM `invoices` FINAL

Validity: pattern rules

Regular expressions check formats: e-mail addresses, postcodes, IBANs, VAT IDs, SKU formats. Count non-empty values that do not match.

SELECT countIf(email != '' AND NOT match(email, '^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$')) AS invalid
FROM `contacts` FINAL

Data freshness checks

Freshness is the age of the newest row. If a sync runs hourly and the newest row is six hours old, something stopped. Use a timestamp from the source (such as updated_at) or the time the row was written.

SELECT dateDiff('hour', max(updated_at), now()) AS age_hours
FROM `orders` FINAL

Set the limit from the business rhythm, not the technical schedule. Orders in a busy shop should be minutes or a few hours old; a table of contracts may legitimately not change for a week. Also decide what an empty table means: for a freshness check, no rows at all should count as a failure.

Volume: row count checks

A minimum catches the classic "table is suddenly empty" case after a failed replace load. A maximum catches runaway imports that append the same data again and again.

SELECT count() AS row_count
FROM `customers` FINAL

Absolute bounds work well for tables that grow slowly. For tables with daily rhythm, count rows per day instead and check yesterday:

SELECT count() AS orders_yesterday
FROM `orders` FINAL
WHERE toDate(created_at) = yesterday()

Custom SQL rules for everything else

Consistency checks, cross-table checks and business logic need custom SQL. The simplest convention: the query returns the number of violations, and anything above zero (or a tolerated maximum) fails.

-- Orders that reference a customer that does not exist
SELECT count() AS orphans
FROM `orders` FINAL
WHERE customer_id NOT IN (SELECT customer_id FROM `customers` FINAL)
-- Paid invoices without a payment date
SELECT countIf(status = 'paid' AND paid_at IS NULL) AS violations
FROM `invoices` FINAL

Write the expectation in the rule name, for example "every order has a known customer", so whoever gets the alert understands it without reading the SQL.

How often to run data quality checks

Run a check shortly after the data can change, and not much more often. Checking a nightly import every five minutes produces load and noise without new information.

Data sourceSensible interval
Sync every 15 minutes (orders, tickets)Every 15 minutes to hourly
Hourly sync (invoices, payments)Hourly
Nightly import or syncDaily, scheduled after the import window
Manual file importDaily or weekly, plus a check right after each import
Slowly changing reference dataWeekly

Alerting: getting failures to the right owner

A failing rule nobody sees is as useless as no rule. Three principles keep alerts useful and avoid alert fatigue:

  • Every table has an owner. The owner is the person or team who can fix the data or talk to the source system's team.
  • Severity decides the channel. Critical rules (duplicate invoices, a stopped revenue sync) go to a channel that is read immediately or create a ticket. Warnings (a few contacts without phone numbers) can go into a daily summary.
  • Alert on change, not on every check. Notify when a rule goes from OK to failed, and again when it recovers. A rule that fails every hour for three days should not send 72 identical messages.

Include the context in the message: table, rule, measured value, threshold and a link to the rows. "12 of 743 contacts have no e-mail" is actionable; "Quality check failed" is not.

Handling failures: a short runbook

  1. Distinguish "failed" from "could not run". A rule that found violations is a data problem. A rule that could not run (missing column, SQL error, table deleted) is a monitoring problem and needs a different person.
  2. Check the source first. Did the sync fail, did someone change an export, did the source system change a field? Most quality failures start upstream.
  3. Look at the bad rows. Turn the rule into a SELECT * with the same condition and look at examples. Patterns (all from one region, all since Tuesday) usually point to the cause.
  4. Fix at the source when possible. Correcting rows in the reporting table helps until the next sync overwrites them. Fix the export, the mapping or the source record.
  5. Adjust the rule if the rule was wrong. A threshold that fails every Monday because of weekend volume is a bad threshold, not bad data. Tune it, write down why, and move on.

Data contracts with source systems

Many quality problems come from changes nobody announced: a field renamed in the CRM, a status value added in the shop, a new export format from the accounting tool. A data contract is a written agreement between the team that owns a source system and the team that uses its data. It does not need special tooling; a short page per source is enough:

  • Schema: which fields are delivered, their types and which are required.
  • Keys: which field identifies a record and is guaranteed to be unique.
  • Allowed values: status values, currencies, units (cents or euros).
  • Freshness: how often data is delivered and how late it may be.
  • Change process: how and how early changes are announced.
  • Contacts: who to call when something breaks, on both sides.

The useful part: each clause of the contract becomes a rule. "Customer ID is required and unique" becomes a not-null and a unique rule; "delivered hourly" becomes a freshness rule with a sensible limit. The rules then check the contract continuously.

Data quality for syncs and imports

Syncs and imports are where most problems enter. A few habits help:

  • Use a key and upsert. Loading by key prevents duplicates when a record is delivered twice; appending without a key is the most common source of duplicates.
  • Check after the first run. Compare the row count with the source system. A large difference usually means pagination or a filter is wrong.
  • Watch for new columns. When a source adds or renames a field, a new column appears. A renamed field means the old column stops being filled, which a not-null rule then catches.
  • Treat file imports as a source too. A manual CSV import deserves the same rules as an automatic sync; our guide from CSV exports to SQL dashboards shows the import side in detail.

Dashboards that show data health

A data health view answers "can I trust the numbers today?" at a glance. Useful elements: the number of rules and how many fail, split by severity; rules that could not run; the age of the newest row per important table; row counts per day for the main tables, so drops and spikes are visible; and a list of failing rules with table, rule and last result.

Put the health view next to the business dashboards, not in a separate tool nobody opens. A small "data as of" tile with the age of the newest row on a revenue dashboard prevents many wrong decisions:

SELECT 'orders' AS table_name, max(updated_at) AS newest_row, count() AS rows FROM `orders` FINAL
UNION ALL
SELECT 'invoices', max(updated_at), count() FROM `invoices` FINAL

Checklist: data quality monitoring

  • Every important table has an owner and a short description.
  • Business keys (invoice number, order ID, customer number) have a unique rule.
  • Required fields have a not-null rule with a clear threshold.
  • Every synced table has a freshness rule matched to its business rhythm.
  • Main tables have a row count check against empty or exploding loads.
  • Cross-table expectations are written as custom SQL rules that return a number of violations.
  • Critical rules reach a channel that is read immediately; warnings go into a summary.
  • Alerts fire on status change and contain table, rule, value and threshold.
  • "Rule failed" and "rule could not run" go to the right people.
  • Each source system has a short data contract, and its clauses exist as rules.
  • Business dashboards show how current the data is.

How Obseria helps

In Obseria Data, the business data platform in Obseria, quality rules are part of the Data area. They check tables that live in Obseria Data, filled by file import, scheduled syncs, workflows or the API. What is available today:

  • Seven rule types: column is filled (empty strings count as missing), column is unique, values in range (minimum and/or maximum), values match a pattern (RE2 regular expression), table is fresh (age of the newest row in hours, based on a chosen timestamp column or the time rows were written), row count in range, and custom SQL whose result must stay at or below an allowed value. The rules use the same read-only SQL as the SQL editor.
  • Severity and interval per rule: warning or critical; checks every 15 minutes, hourly, every 6 hours, daily or weekly. A new rule is checked right away, and rules can be paused, resumed, run individually or all at once.
  • Suggested rules: for a table, Obseria can propose obvious checks, such as uniqueness of the key column, filled and well-formed e-mail columns, non-negative amounts, freshness within 24 hours and a non-empty table.
  • Clear results: each rule shows OK, failed or "could not run", with the measured value, a short explanation such as "12 of 743 rows have no email" and the time of the last and next check. The Data overview shows how many rules fail, and each table has its own Quality tab.
  • Alerts through workflows: when a rule fails or cannot run, Obseria raises the event "Quality rule failed (Data)", only when the status changes, not on every check. A workflow in Obseria Workflow with this trigger sends the message by e-mail, Slack or Teams, creates a ticket or starts any other process; conditions on table or severity route it to the right owner. Without such a workflow, failures are visible in the app but nobody is notified.
  • Syncs and imports: data syncs load by key and show failed runs with their error message, and the event "Table updated (Data)" reports how many rows were written and which new columns appeared, so a workflow can check new data right after each load.
  • Health on dashboards: business dashboards can show freshness and row counts of your tables with SQL tiles like the example above.

Limits to know: volume checks use fixed bounds, not learned baselines; there is no dedicated rule type for schema changes; failing rows are reported, not blocked or quarantined; and rule results are shown in the app rather than as a table you can query. For the technical side of databases, brokers and jobs, use Obseria data observability. To try rules on your own tables, start a free trial.

Frequently asked questions about data quality monitoring

What is the difference between data quality monitoring and data observability?

Data quality monitoring checks the content of tables: missing values, duplicates, wrong formats, stale or implausible data. Data observability in the operational sense watches the systems that move data, such as databases, queues and scheduled jobs. A job can run without errors and still load bad data, so both views complement each other.

Which data quality rules should I start with?

Start with three per important table: a unique rule on the business key, a freshness rule matched to the update rhythm and a row count rule against empty loads. Add not-null rules for the two or three fields your reports depend on. Expand once these run quietly.

How do I set up data freshness checks?

Pick the timestamp that tells you when a record was last changed or loaded, measure the age of the newest row and set a limit from the business rhythm, for example a few hours for orders and a day for nightly imports. Run the check at least as often as the limit, and treat an empty table as a failure.

Do I need a data contract for every source?

A short one, yes, at least for sources your key figures depend on. It can be half a page: fields, keys, allowed values, delivery rhythm, change process and contacts. Each clause then becomes a rule that checks the contract continuously.

Should failing data be blocked from reports?

Sometimes, for critical financial figures, a report should not go out while a critical rule fails. More often it is enough to show clearly that the data is affected, fix the source and tell the people who use the report.

Share

Observability that delivers answers.

Start for free with OpenTelemetry, no credit card required.