Streaming Data Quality
Checking quality without the luxury of a re-run
Data quality in streaming is harder than in batch because there's no 're-run': expectations, anomaly detection and out-of-band correction must run inline, with lag as a first-class metric alongside freshness.
What you will learn
- Apply expectations inline on streaming events
- Detect anomalies and drift with windowed metrics
- Build correction paths for bad and late data
What is this?
Streaming quality checks run inline: each event (or batch) is validated against expectations (schema, nulls, ranges, value distributions), anomalies are detected by comparing windowed metrics, and bad events are routed to a dead-letter or correction lane. Because streams can't be 're-run yesterday', the quality of each arrival window matters as much as the final result.
Why do you need it?
- Batch QA flows (re-run, fix, redeploy) don't exist; a broken producer emits bad events for days.
- Stream consumers (alerts, live dashboards) act on first pass — quality must gate there.
- Lag, duplication and ordering IS data quality for streams — not just value correctness.
- Drift detection catches slow degradation before users see wrong numbers.
Mental model
An airport security scanner per passenger
Inline stream checks
You can't re-screen the whole terminal later — each passenger is inspected as they arrive (schema/range check), flagged anomalies alert the team immediately (anomaly detection), and the false positives go to a slow lane (dead letter) for retreading later.
How it works
- Expectation checks run per-event/per-window: non-null, type, allowed values, range, cardinality, referential.
- Anomaly detection compares windowed rates (events/sec, null-rate) to rolling baselines (z-scores, EMA).
- Bad events route to a DLQ (topic) with the reason; valid events continue on the main path.
- Late-data and skew handling feeds corrections back (allowedLateness + late stream).
- Quality metrics themselves are streamed (dashboards for error-rate, lag, drift) and alerted on.
Inline quality gates in the stream.
In production
- A clickstream pipeline drops events with user_id null to a DLQ and alerts on the null-rate gate.
- An order stream detects a 30% drop in event volume vs the rolling baseline, paging before the dashboard lies.
- A metrics event stream re-synced with allowedLateness and a late-data lane for exact reporting.
Best practices
- Check events as they arrive and treat the DLQ as a first-class consumer (not 'a folder').
- Alert on quality rates, not absolute counts — a friendly baseline prevents noise.
- Encode quality metrics in the stream itself for self-observability.
- Design for latency: inline matching should run at wire speed, not asynchronously after deadlines.
Common mistakes
- Letting 'quality' run only in nightly batch — by then worst damage is done.
- Using a DLQ nobody owns — bad events sit there forever, invisible.
- Alerting on absolute numbers that spike on every traffic burst (false alarms burn focus).
- Checking only value correctness but not ordering/duplication/lag quality.
Common issues
Alerts fire every traffic spikeAbsolute thresholds instead of baseline-relative anomaly detection
Use rolling-window baseline + z-score/EMA so dots scale with normal variance.
Bad events keep flowing downstream past your checkCheck ordering: schema registry passes but value validation runs too late
Honor quality gates inline before branching; test the DLQ path end to end.
Metrics drift on late eventsLate arrivals reprocessing closed windows without corrections
allowedLateness + a late-data lane; re-emit corrected facts with watermark timestamps.
Debugging tips
- A metric dropping suddenly → compare production rate to baseline; sudden dip = producer or topology issue.
- DLQ filling → check the newest schema change or a source-side change (types, null policy).
- Late data suddenly arriving → check consumer lag and scheduling (the quality metric 'lag').
- Suspicious ordering → keying change or partition rebalance; verify keyBy stability.
Interview checkpoint
Quick quiz
The best first stop for an event that fails schema or value checks in a stream is...
Lag is a data-quality metric for streaming, not just an ops metric.