Audit a Feature Pipeline for Silent Failures, Then Design for Freshness
Machine LearningModel answerLast updated
Spot every category of production risk in a passing-tests feature pipeline PR, then choose the right serving architecture for batch, near-real-time, and request-time features.
You are reviewing a pull request that rewrites part of a feature pipeline — the code responsible for turning raw event data into model inputs. Every unit test in the PR is green. The interviewer wants two things from you.
Part 1: Walk through the PR and explain what could silently break in production, even though the tests pass. Rank the issues by potential impact, and for each one describe how you would catch it before the change ships or detect it after.
Part 2: The same features need to be served to an online model under three different freshness requirements: values computed once a day are fine, values must reflect events from the last few minutes, and values depend on the live request itself. For each scenario, describe the architecture, its trade-offs, and how you keep training and serving consistent.
Setup and clarifying questions
Before diving in, a strong reviewer asks:
- Are these features used at training time, inference time, or both? Does the same code path compute them in both places?
- What are the upstream data sources — event streams, warehouse snapshots, or both — and how late can events arrive?
- Is this a scheduled batch job, a streaming job, or a function called at request time?
- What does the model or downstream system do when a feature value is missing or unexpectedly stale?
The answers shape which risks matter most and which serving tier is even feasible.
What Part 1 should cover
Identify the categories of production risk that passing unit tests cannot exercise. For each risk:
- Describe what it looks like in code
- Explain how it manifests in production (model behavior, pipeline failure, or silent data corruption)
- Propose a pre-release check or post-release monitor
Focus on: temporal correctness (leakage, late events, window boundaries), data quality (nulls, duplicates, join fan-out, schema drift), training-serving consistency, and operational hazards (skew, memory, idempotency).
What Part 2 should cover
For each freshness tier, explain: where features are stored and how they are computed, what latency and cost profile to expect, what consistency guarantees are possible, and how the system degrades gracefully when the fresh path is slow or unavailable.
Hints
Hint 1
The most damaging bugs in feature pipelines are silent: the code runs, the tests pass, and the model quietly gets worse. Start your review by asking what the unit tests could not possibly have tested — future data, late arrivals, production data volumes, real upstream schemas.
Hint 2
For serving freshness, think in three tiers: precomputed batch values in a low-latency key-value store, streaming aggregates maintained by a job that runs continuously, and on-demand features computed inline at request time. Each tier adds freshness but also adds cost, latency, and operational surface area. Match the tier to what the feature actually needs.
Hint 3
Training-serving skew is a thread that runs through both parts. In Part 1, ask whether the pipeline that generates training labels uses the same code and the same data snapshot as the pipeline that serves features online. In Part 2, ask how you log exactly the feature values that were served so you can reconstruct them for retraining.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Part 1 — Production risks in a passing-tests PR
Why tests pass and production breaks
Unit tests run on fixed, small, clean fixtures. Production has late events, skewed distributions, schema changes, timezone ambiguities, and data volumes that expose entirely different code paths. The goal of a PR review is to surface what the fixtures could not exercise.
Risk 1: Temporal leakage (highest impact, silent)
What it looks like in code: A window boundary uses event_time <= label_time instead of event_time < label_time, or a join pulls in a snapshot table keyed by processing date rather than event date. A rolling aggregate uses NOW() instead of the observation timestamp passed in as a parameter.
How it surfaces: The model appears to perform better than it should in offline evaluation and then degrades significantly in production. This is one of the hardest problems to debug after the fact.
How to catch it: Code review should trace every timestamp — ask "where does this value come from, and can it ever be later than the label timestamp?" Add a leakage assertion to the training harness that verifies no feature value was computed using information from after the label time. Temporal unit tests should use a fixed as_of timestamp and assert that changing it changes the output.
Risk 2: Training-serving skew (high impact, silent)
What it looks like in code: The offline pipeline uses Spark with mean() imputation trained on the full training set, but the online serving path uses a hardcoded fallback value, or calls a different library that handles edge cases differently (e.g., integer vs. float division, NaN propagation).
How it surfaces: Predictions at serving time are systematically different from what the model was trained to expect, even on identical raw inputs. Effect size varies — sometimes it is negligible, sometimes catastrophic.
How to catch it: Log the feature values actually served alongside predictions. Periodically replay a sample of production requests through the offline pipeline and compare distributions. Keep training and serving in the same code path wherever possible; a feature store with a single definition executed in both environments eliminates most of this risk by construction.
Risk 3: Late and out-of-order events
What it looks like in code: A daily aggregation job runs at midnight and closes the window immediately, but events for the same day can arrive up to six hours late due to upstream pipeline delays.
How it surfaces: Features computed for recent time windows are systematically under-counted compared to what they will look like once all events have arrived. A model trained on complete data is served incomplete data for recent users.
How to catch it: Define an explicit event-time SLA and test the pipeline at various arrival delays. Expose a data_completeness_fraction metric per window and alert when it drops below a threshold. Consider closing windows only after the SLA has passed, or computing features incrementally and recomputing when late data arrives.
Risk 4: Data quality — nulls, duplicates, join fan-out
What it looks like in code: A left join on a dimension table with a non-unique key silently multiplies rows. A new upstream column is added with a high null rate. An at-least-once event source delivers duplicates that inflate counts.
How it surfaces: Aggregate features are inflated, join results are larger than expected consuming excess memory, or null values propagate to the model as zeros or errors.
How to catch it: Add row-count assertions before and after joins. Assert expected null rates per column. Deduplicate on a stable event ID before aggregating. Emit data quality metrics (null rate, distinct count, min/max) and alert on deviations from a rolling baseline.
Risk 5: Operational hazards — skew, memory, idempotency
A single high-cardinality key (one user with millions of events) causes a partition to spill or OOM. The pipeline is not idempotent, so a failed rerun writes duplicates. A backfill overwrites features for dates that already had correct values.
How to catch it: Profile key cardinality in staging on a production-sized sample. Write the pipeline to overwrite by partition key so reruns are safe. Test a backfill against a staging environment before running it in production.
Part 2 — Serving features at three freshness tiers
Tier 1: Batch features (day-old values acceptable)
Architecture: An offline job — Spark, dbt, or similar — runs on a schedule (hourly or daily), writes results to an online key-value store (Redis, DynamoDB, Bigtable). The model fetches feature values by entity key at inference time with sub-millisecond latency.
Trade-offs: Low cost, simple to operate, easy to version and audit. Staleness is bounded by the job cadence — fine for slowly changing features like a user's 30-day purchase history, but wrong for anything that needs to reflect today's activity.
Consistency: The training pipeline writes the same features to the offline store (e.g., a data warehouse). The online store is a point-in-time copy. As long as both reads use the same snapshot, skew is minimal.
Tier 2: Near-real-time features (last few minutes)
Architecture: A streaming job — Flink, Spark Structured Streaming, or Kafka Streams — consumes events from a message bus and maintains running aggregates in a low-latency store. Values are updated continuously and read at inference time.
Trade-offs: Much fresher, but meaningfully more expensive and operationally complex. The streaming job must handle late arrivals, reprocessing, and state management. Aggregates in the stream may differ from those computed in batch on the same raw data due to different processing semantics — this is a major source of skew.
Consistency: Log the feature vector actually served with each prediction. Use a feature platform (Feast, Tecton, Vertex Feature Store) that enforces a single feature definition and executes it in both the batch and streaming path. When retraining, use point-in-time correct joins against the logged feature values rather than recomputing from raw events.
Fallback: If the streaming job falls behind or fails, fall back to the most recent batch value rather than failing the request. Expose a feature_age_seconds metric and alert when it exceeds an SLA.
Tier 3: Request-time (on-demand) features
Architecture: Features that depend on the live request — search query embedding, session-so-far features, cross-feature interactions between the request context and stored user state — must be computed inline in the serving path.
Trade-offs: Maximum freshness, but adds latency directly to the p99 of the serving endpoint. Complex on-demand computation can make the feature layer the bottleneck. This tier should be reserved only for features that genuinely cannot be precomputed.
Consistency: On-demand features that call an external model or service introduce a dependency chain. Cache aggressively where possible. Log inputs and outputs so the computation can be replicated offline for retraining.
Common mistakes across both parts
- Treating a green test suite as evidence of correctness in production rather than correctness on fixtures
- Using
NOW()orCURRENT_DATEinside a feature function instead of an explicitas_oftimestamp - Assuming the streaming and batch paths will produce identical results without empirical validation
- Not logging the features that were actually served, making it impossible to retrain without recomputing
- Skipping fallback logic for the streaming tier and letting a lag spike propagate to the model as missing values