Project 05 · Data quality

Data Quality and Observability Platform

Bad data is cheaper to catch at the door than in a board deck. This platform watches 148 tables across the warehouse and the lake. Great Expectations suites validate each batch inside the PySpark job that writes it, Monte Carlo learns every table's normal freshness and volume and flags anomalies no rule anticipated, and records that cannot be parsed go to a dead-letter queue instead of disappearing. All results land in one metrics store that Grafana and this dashboard read, and incidents go to the owning team with the failing rows attached.

  • Great Expectations
  • PySpark
  • Monte Carlo
  • Prometheus
  • Grafana
Sample data Last 30 days · Sep 7 – Oct 6, 2026 Download data (CSV)

Volume vs expected: analytics.fct_orders

Rows loaded per hour, last 7 days, with the learned expected range

Freshness against SLA

Time since last update. The white mark is each table's SLA.

Failed checks per day

By quality dimension

Dead-letter queue by reason

Records rejected in the last 30 days

Incidents

Opened automatically from checks and anomaly monitors

Great Expectations suites

Critical suites block the write when they fail

How it works

Rules for what we know can break, learning for what we don't, and a home for every rejected record.

  1. 01 · Validate on write

    Great Expectations + PySpark

    Each batch is checked before it is published: nulls, ranges, uniqueness, row counts. Critical suites block the write.

  2. 02 · Route bad records

    Dead-letter queue

    Records that fail parsing or a contract go to a Kafka DLQ topic with the reason attached, so nothing disappears.

  3. 03 · Learn normal

    Monte Carlo

    Learns each table's usual freshness, volume and schema, and flags changes nobody wrote a rule for.

  4. 04 · Measure

    Prometheus

    Check results, table ages and DLQ counts become metrics labelled with the table and its owner.

  5. 05 · Alert

    Grafana

    Freshness SLAs alert the owning team's channel with a runbook link; dashboards per domain.

  6. 06 · Respond

    Incidents

    Each alert opens an incident with the failing rows, the lineage and the reports downstream.

  • Contracts at the producer. Critical suites run inside the job that writes the data, so a failure stops publication instead of paging someone after the numbers are already wrong.
  • Rules plus learning. Hand-written checks cover what we know can break; anomaly monitors cover the rest, like the Oct 2 volume drop that no rule anticipated.
  • Nothing silently dropped. Every rejected record lands in the DLQ with its reason, topic and offset. A daily job reports counts by producer and replays records once they are fixed.
  • Owners, not channels. Every table has an owning team in its metadata, so alerts reach the people who can fix the problem, with a runbook link.

Data model

Check results and rejected records are data too: both are tables with an owner and a retention policy.

dq.check_resultsIceberg table · one row per check run
run_idstring
Validation run
table_name / ownerstring
Table checked and the team that owns it
check_name / dimensionstring
For example order_id_unique, Uniqueness
passedboolean
Result
observed_value / thresholddouble
What was measured and the limit
run_tstimestamp
When the check ran
dlq.recordsKafka topic, mirrored to a table
source_topic / partition / offsetstring / int / bigint
Exactly where the record came from
reasonstring
Why it was rejected
producerstring
App or service that sent it
payloadstring
The original record, untouched
rejected_attimestamp
When it was routed to the DLQ
check_results_dailyAggregate · the CSV download
datedate
Day
dimensionstring
Validity, Freshness, Volume, Distribution, Uniqueness or Schema
checks_run / checks_failedint
Counts for the day
pass_ratedouble
Share of checks that passed

Key code

Validation inside the write path, the dead-letter routing, and the freshness alert rule.

Runs the critical suite on each batch inside the PySpark job. Failing batches go to quarantine; results become metrics.

import great_expectations as gx
import great_expectations.expectations as gxe
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
from pyspark.sql import functions as F

context = gx.get_context(mode="file", project_root_dir="gx")

suite = context.suites.add_or_update(gx.ExpectationSuite(
    name="orders.critical",
    expectations=[
        gxe.ExpectColumnValuesToNotBeNull(column="order_id"),
        gxe.ExpectColumnValuesToBeUnique(column="order_id"),
        gxe.ExpectColumnValuesToBeBetween(column="total_usd", min_value=0, max_value=50_000),
        gxe.ExpectColumnValuesToBeInSet(column="status", value_set=["placed", "paid", "shipped", "cancelled"]),
        gxe.ExpectTableRowCountToBeBetween(min_value=1_000, max_value=2_000_000),
    ],
))

batch_def = (
    context.data_sources.add_or_update_spark(name="spark")
    .add_dataframe_asset(name="orders_batch")
    .add_batch_definition_whole_dataframe("per_run")
)
validation = context.validation_definitions.add_or_update(
    gx.ValidationDefinition(name="orders.critical", data=batch_def, suite=suite)
)


def publish_if_valid(df, run_id: str) -> bool:
    result = validation.run(batch_parameters={"dataframe": df})

    registry = CollectorRegistry()
    passed = Gauge("dq_checks_passed", "Checks passed", ["table", "suite"], registry=registry)
    failed = Gauge("dq_checks_failed", "Checks failed", ["table", "suite"], registry=registry)
    stats = result.statistics
    passed.labels("analytics.fct_orders", "orders.critical").set(stats["successful_expectations"])
    failed.labels("analytics.fct_orders", "orders.critical").set(stats["unsuccessful_expectations"])
    push_to_gateway("pushgateway:9091", job="dq-orders", registry=registry)

    if result.success:
        df.writeTo("lake.analytics.fct_orders").append()
        return True

    # Keep the batch for inspection and replay; downstream readers never see it.
    df.withColumn("run_id", F.lit(run_id)).writeTo("lake.quarantine.fct_orders").append()
    return False

Engineering notes

Caught before the dashboards were

At noon on Oct 2 an upstream API outage cut hourly order volume by about 80%. The anomaly monitor opened INC-2286 six minutes later, before anyone looked at a report, and a backfill closed it in three hours.

A duplicate load, not a sales spike

At 14:00 on Oct 5, volume jumped 95%. The order_id uniqueness check showed a retried batch had loaded twice; it was removed before finance saw inflated numbers.

Detection got faster

Mean time to detect fell from 9 to 7 minutes after freshness checks for critical tables moved from hourly to every 10 minutes.

The DLQ is a to-do list

Of 48K rejected records, 38% were schema mismatches from one mobile app version. It was fixed in the next release and 17K records were replayed.

About the data. Every number on this page is sample data from a seeded generator written for this project. It is shaped to behave like a real workload, with daily peaks, late events and the odd incident, but it does not come from any employer or client. Download it as check_results_daily.csv or read data.json.