Build a Data Quality and Observability Layer for Live Pipelines
System DesignModel answerLast updated
Design an end-to-end system for validating, monitoring, and recovering from data failures across both batch and streaming pipelines in a production environment.
The Scenario
Your team owns the data infrastructure for a financial firm where downstream systems — risk models, position tracking, and trading signals — depend on fresh, accurate data arriving on time. Bad data reaching these systems has real consequences: incorrect risk exposure calculations, wrong P&L, or flawed signals.
You have been asked to design a production-grade framework covering pipeline orchestration, data quality validation, and observability. The system must handle both nightly batch workflows and continuous streaming pipelines.
What to Address
1. Orchestration and dependency management
How do you coordinate pipelines that depend on one another? Upstream jobs must complete and pass quality checks before downstream jobs are allowed to proceed. Describe how you model dependencies, handle backfills, and enforce idempotent execution.
2. Data quality checks
What checks do you build into the pipeline? At minimum, discuss:
- Upstream dependency checks (is the upstream partition ready and certified?)
- Schema checks (are column names, types, and nullability as expected?)
- Null and validity checks (required fields present, values in valid ranges?)
- Primary key checks (no duplicates, no missing keys?)
- Volume and threshold checks (row count within expected bounds versus a rolling baseline?)
How are check results acted on? What separates a blocking failure from a non-blocking warning?
3. Observability framework
What does your observability layer track and expose? Think about freshness, data lineage, schema drift, distribution metrics, alerting, and incident workflow. How does lineage help reduce alert noise when something breaks upstream?
4. Handling partial validation failures in streaming
A streaming pipeline is processing events and 2% of records are failing validation. Do you stop the entire pipeline? Walk through your decision process and describe your handling strategy in detail.
Expectations
This is a design question with no single right answer. Strong responses will:
- Scope the problem before designing (scale, SLAs, criticality tiers)
- Make concrete trade-offs rather than listing every possible feature
- Show awareness of operational realities: alert fatigue, backfill correctness, consumer impact
- Give a nuanced answer to the streaming failure question rather than a blanket yes or no
Hints
Hint 1
Before diving into components, define at least two criticality tiers for your datasets and let those tiers drive different SLAs, alerting behavior, and failure responses. A position table and a clickstream table should not be treated the same way.
Hint 2
For the streaming failure question, separate the act of consuming records from the act of publishing results to downstream consumers. Stopping consumption and stopping publication are two different decisions with very different consequences.
Hint 3
Think about the Write-Audit-Publish pattern: data is written to a staging area, quality checks run against the staged copy, and only a passing snapshot gets promoted atomically. This keeps consumers from ever touching unvalidated data.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Step 0: Clarify Before Designing
A strong answer starts with a few scoping questions rather than jumping straight to architecture.
- Batch scale: assume several hundred DAGs and thousands of tables — vendor files, reference data, end-of-day positions — with hard SLAs (for example, risk tables ready by 6:00 AM local time).
- Streaming scale: assume tens of thousands of events per second at steady state, spiking to several hundred thousand at market open. End-to-end p99 latency target under 5 seconds.
- Criticality tiers:
- T0 — positions, trades, prices. Wrong data is worse than late data.
- T1 — research and alternative data. Lateness is tolerable; quality still matters.
- T2 — exploratory datasets. Best-effort.
- Non-functional: idempotent reruns, full auditability, and a strict cap on actionable alerts per team per day (around 5) to prevent alert fatigue.
1. Orchestration and Dependency Management
Asset-based scheduling is the right mental model. Rather than triggering downstream jobs on a wall-clock schedule, downstream jobs trigger when an upstream partition is published and certified by the quality layer. Tools like Dagster assets or Airflow Datasets support this natively; custom implementations publish an event to a metadata store that sensors poll.
Every dataset is keyed by (dataset_name, partition), for example eod_positions/2024-06-03. A job declares which upstream partitions it needs before it can run. This makes backfills trivial: rerunning a date range replays the exact dependency graph for those partitions.
Idempotency is non-negotiable. Every write must be a partition-overwrite or a keyed MERGE, never an append. Retries must produce the same result as the first run.
SLA tracking should sit at the orchestrator level. Each asset carries an expected-ready timestamp. The orchestrator computes the critical path across the dependency graph and raises an early warning when a slow upstream is likely to cause a downstream SLA miss — not after the SLA is already breached.
Retry policy: exponential backoff for transient infrastructure failures; immediate hard fail (no retry) for quality failures. Retrying a quality failure just delays the alert.
2. Data Quality Checks
Quality checks are defined in a data contract per dataset, versioned alongside the pipeline code. A minimal contract looks like this:
dataset: eod_positions
tier: T0
owner: risk-data
primary_key: [account_id, symbol, as_of]
freshness_deadline: "05:30 America/New_York"
checks:
- type: upstream_certified
datasets: [trades, security_master]
severity: block
- type: not_null
columns: [account_id, symbol, qty]
severity: block
- type: unique
columns: [account_id, symbol, as_of]
severity: block
- type: row_count_change
max_pct: 15
baseline_days: 20
severity: block
- type: referential
column: symbol
ref: security_master.symbol
max_miss_pct: 0.1
severity: warn
- type: anomaly
metric: sum(abs(qty))
method: seasonal_zscore
z_threshold: 4
severity: warn
| Check category | What it catches |
|---|---|
| Upstream dependency | Upstream partition not yet certified; vendor file missing |
| Schema | Column removed, type changed, nullability widened — caught by a schema registry before any write |
| Null / validity | Missing required fields, prices ≤ 0, malformed identifiers |
| Primary key | Duplicate rows, missing join keys |
| Volume / threshold | Row count deviating from a seasonally-adjusted rolling baseline |
| Cross-system | Summed notional mismatches against the source system or broker file |
Severity drives action. A block failure halts publication. A warn failure publishes the data with a quality flag set, and routes an alert to the owner without stopping downstream jobs.
Write-Audit-Publish is the execution pattern. Data lands in a staging snapshot (Iceberg or Delta table branch). Checks run against the staged copy. Only on a full pass does the production read pointer swap atomically. Consumers never touch data that has not cleared the quality gate.
3. Observability Framework
Observability covers five dimensions: freshness, volume, schema, distribution, and lineage. These feed into a metadata store (a relational database plus a time-series store), which powers dashboards, alerts, and incident management.
Key metadata tables:
datasets— owner, tier, contract versionruns— run ID, dataset, partition, status, start/end, code versioncheck_results— run ID, check name, observed value, threshold, pass/faillineage_edges— upstream → downstream relationships, emitted by the compute layer via OpenLineageincidents— open issues, linked to affected assets and owners
Profiling runs on every batch. Each run emits column-level statistics: null rate, distinct count, min/max, quantiles. These feed anomaly detectors and serve as the distribution baseline for future runs.
Lineage-driven impact analysis is what separates a useful observability system from a noisy one. When a T0 check fails, the system walks the lineage graph, marks all downstream assets as stale or suspect, and suppresses alerts for those assets. Owners receive one root-cause alert instead of a cascade of symptom alerts from every affected consumer. This is the single most effective lever against alert fatigue.
Streaming metrics to track continuously: consumer lag, events/s per partition, validation failure rate per source, watermark delay, and DLQ depth. Each of these should have tier-based thresholds.
Alerting rules: T0 failures page on-call immediately with a link to the failing rows, the lineage view, and a runbook. T2 failures go into a daily digest. Every alert is actionable by default; noise is a first-class bug.
4. Streaming: 2% Failure Rate — Stop or Continue?
Do not stop consumption. Decide separately whether to pause publication.
Stopping consumption from Kafka causes consumer lag to build. You lose the ability to replay from a known offset and may push the topic past its retention window. Always keep consuming; route bad records to a dead-letter queue (DLQ) immediately.
Whether to pause downstream publication depends on the following decision process:
Step 1 — Is 2% elevated? If the historical baseline for this feed is 1.8–2.2%, nothing unusual is happening. If the baseline is 0.05% and you just jumped to 2%, something broke.
Step 2 — Are failures random or concentrated? Group failures by source, producer instance, partition, schema version, and symbol. A single feed or a single recent producer deploy causing all the failures means you can isolate that slice and let the rest flow. Failures spread uniformly across all partitions suggest a contract-level break.
Step 3 — Which check failed? A deserialization or schema failure almost always means a breaking producer change. A missing optional enrichment field is benign. The type of failure determines whether the problem is fixable in flight.
Step 4 — What does a 2% gap mean downstream? For a T0 dataset like trades flowing into position calculations, a 2% miss means positions, risk, and P&L are wrong. That warrants pausing publication to T0 consumers while the team investigates. For a T2 clickstream aggregate, a 2% gap is acceptable and the pipeline should continue.
Step 5 — Can failed records be recovered? If failures are due to a late reference-data join that will be available shortly, the DLQ can be replayed once the dependency arrives. If they are corrupt at the source, they cannot.
Practical handling strategy:
- All invalid records route to a DLQ with full context: the original payload, the check that failed, the timestamp, and the source partition.
- A DLQ depth alert fires if the backlog grows beyond a configured threshold.
- The pipeline emits a real-time quality metric (failure rate per source) consumed by the observability layer.
- T0 downstream consumers receive a stale-data signal so they can freeze outputs rather than act on incomplete data.
- The on-call team gets one alert with the failure breakdown, not one alert per bad record.
Common mistakes to avoid:
- Treating all streaming failures the same regardless of dataset tier
- Stopping the entire pipeline (including consumption) on any validation error
- Alerting at the individual record level rather than at the aggregate rate level
- Not separating the DLQ retry path from the live path, which causes ordering issues on replay