How do you build reliable data pipelines for ML?
Written by the mlprep team · Updated
How do you build data pipelines for ML that are reliable enough to feed production training and serving? What failure modes do you design against?
ML data pipelines fail in two ways: loudly (the pipeline crashes, training doesn't happen) and silently (the pipeline runs successfully but produces bad data, the model quietly degrades). Silent failures are far more dangerous. The goal of a reliable pipeline is to catch both.
ML-specific requirements#
Beyond correctness, ML pipelines need:
- Point-in-time correctness: features computed for training must use only data available at the label timestamp (no leakage)
- Reproducibility: re-running the pipeline on the same input snapshot should produce identical output
- Data quality guarantees: null rates, value ranges, and distributions must stay within expected bounds
- Versioning: changes to feature logic must be tracked so you can reproduce any historical training run
Idempotency#
Every pipeline stage should produce the same output if run multiple times with the same input. This means: no side effects based on current state, writes that overwrite rather than append on re-run, and operations safe to retry after partial failure.
Non-idempotent pipelines are a nightmare in production — a failed run leaves you with partially-written data, and re-running makes it worse. Design with INSERT OVERWRITE (not INSERT INTO), atomic file moves, and partition-aware writes.
Schema and distribution validation#
At every stage boundary, validate:
- Schema: expected columns exist, correct types, no unexpected nulls in required fields
- Statistics: distributions are within expected ranges (null rate, mean, quantiles, cardinality for categoricals)
- Volume: number of rows is within expected range (sudden drop = upstream issue)
Great Expectations and Soda are popular frameworks. Fail fast: if validation fails, halt the pipeline and alert — don't let bad data propagate to training.
Orchestration#
Airflow, Prefect, and Dagster schedule and execute pipelines. Key features you need:
- Dependency graph: stage B runs only after stage A succeeds
- Backfilling: re-run historical date ranges cleanly
- Retry with backoff: transient failures shouldn't kill a run
- Alerting: failures notify on-call, not just log to a file
Change data capture#
For streaming or frequently-updated data, change data capture (CDC) tracks row-level changes from the source database (inserts, updates, deletes) and propagates them to the feature store. Tools like Debezium or Fivetran handle this. Without CDC, you either poll (expensive, delayed) or miss updates entirely.
You mentioned silent failures are worse — what does a silent data quality failure look like in practice, and how do you catch it before it reaches training?
Silent failures look like normal pipeline runs in every system metric: the job finished, processed the expected number of rows, wrote output files. But the data is wrong.
Real examples#
Null explosion: a new user segment started being created differently upstream — a field that was always populated for old users is null for 40% of new users. Your null rate check wasn't tight enough (threshold was 20%, you were at 5%, now at 42%). The model was never trained on null values for this feature. Predictions for new users are garbage.
Silent join drop: you join user events to user profiles on user_id. An upstream schema migration changed user_id to be padded with zeros for new users. The join silently fails to match, dropping 30% of recent users from training. Recall on new users drops. You don't notice for two weeks until you investigate why new user performance is degrading.
Future data leakage: a timestamp bug in a feature computation uses event_time instead of processing_time. For events near midnight, some "yesterday" events are labeled as "today." Your model trains on slightly-future data for ~3% of examples, inflating offline metrics. The production model underperforms compared to what eval suggests.
How to catch it#
Layer your checks:
-
Schema checks: run immediately after pipeline output. Every expected column exists, types match, no unexpected nulls in required fields. This catches most schema drift within minutes.
-
Statistical checks: compare feature distributions against a rolling baseline (e.g., past 7 days). Flag if null rate, mean, or quantile moves outside 3 standard deviations. Catches null explosions and distribution shifts.
-
Volume and join checks: assert that output row count is within expected range (e.g., within 10% of yesterday). Assert that join match rate is above threshold (if you join two tables, at least 95% of left-table rows should find a match).
-
End-to-end smoke test: run a mini training job on the fresh data and assert that loss is in a sane range. The most expensive but catches interactions between multiple features.
Alert on any failure before the data reaches training. A blocked training run is a much better outcome than a silently degraded model.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
ML data pipelines fail loudly (crash) or silently (bad data, model degrades). Silent failures are worse. Make pipelines idempotent (same output on re-run), validate schema and statistics at every stage boundary, and fail fast before bad data reaches training. The most dangerous failures are silent drops in join coverage, null explosions for new user segments, and leakage from timestamp bugs — none of which surface in system-level metrics.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How do you handle schema evolution in a data pipeline without breaking downstream models?
- What's the difference between batch and streaming pipelines for ML, and how do you decide which to use?
- How do you backfill a feature that didn't exist when the model was originally trained?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions