End-to-End ML System Design Questions
Designing a complete machine learning system from problem to production. Covers the components and architecture of a production ML system, data flow from ingestion to serving, scalability, and integration of models into a larger product. Emphasizes the whole-system design tradeoffs that appear in ML system-design interviews.
What is training-serving skew, what typically causes it, and how would you go about detecting it before it quietly degrades a live model?
Sample Answer
Direct answer
Training-serving skew is when a model's live input features differ, even subtly, from the features it was trained on, so the model performs worse in production than its offline metrics predicted even though the model itself never changed. It is typically caused by two separate code paths, a batch job for training and an online service for serving, that compute "the same" feature slightly differently, or by data that was available at training time but is late, missing, or defined differently at serving time. Because the model artifact is unchanged, this failure is invisible to code review of the model itself and only shows up as a gap between offline evaluation and live outcomes.
Structured elaboration
Common causes:
- Feature computation divergence: different null handling, rounding, or time windows between an offline Spark-style job and an online service implementing "the same" feature.
- Data availability and timing skew: a feature depends on data that arrives late in production though it was fully present at training time, or the reverse, a feature that used information not truly available until after the label.
- Preprocessing divergence: normalization, tokenization, or categorical encoding applied in training but re-implemented, imperfectly, in the serving path.
- Environment nondeterminism: differing library versions or numeric precision between the training environment and the serving container.
- Population shift: the live traffic distribution differs from the logged historical traffic the model trained on; not a code bug, but the same symptom of an offline-online gap.
Detection, two complementary strategies:
- Structural, pre-deploy: replay the exact serving code path against historical inputs and diff the resulting feature vectors against what the training pipeline produced for the same keys and timestamps. This catches skew before it ever reaches production.
- Live, statistical: continuously compare each feature's serving-time distribution against its training-time distribution, and separately track the gap between offline evaluation metrics and live business or proxy metrics. A widening offline-online metric gap with an unchanged model version is the single strongest live signal of skew.
A standard distributional-shift metric for the second approach is the population stability index (PSI), computed by bucketing a feature's values and comparing actual (serving) proportions against expected (training) proportions per bucket:
PSI=i=1∑k(ai−ei)ln(eiai)where ai is the actual (serving) proportion of observations in bucket i, ei is the expected (training) proportion in that same bucket, and k is the number of buckets.
Worked example
Suppose a single feature is bucketed into "low" and "high," with a training (expected) distribution of e=(0.7,0.3) and an observed serving (actual) distribution of a=(0.5,0.5).
PSI=(0.5−0.7)ln(0.70.5)+(0.5−0.3)ln(0.30.5) ln(0.70.5)≈−0.3365,ln(0.30.5)≈0.5108 PSI≈(−0.2)(−0.3365)+(0.2)(0.5108)=0.0673+0.1022≈0.169By the commonly used industry convention, a PSI under 0.1 is treated as negligible shift, 0.1 to 0.25 as a moderate shift worth investigating, and above 0.25 as a significant shift. A PSI of about 0.169 sits in the moderate range: enough to open an investigation into whether this is skew or a genuine, harmless population change, not yet enough on its own to declare the model broken.
Trade-offs and pitfalls
A replay test catches skew introduced by a code change before deployment, but it cannot catch a live shift caused by an upstream data source changing after deployment; only the distributional monitor catches that half. Distributional monitors need a stable reference distribution and get noisy on low-volume or seasonal features, so a naive fixed PSI threshold will false-positive on a real, expected demand shift (a holiday spike, for instance) that is not a bug at all; thresholds need to account for known seasonality rather than firing on every deviation. Numeric nondeterminism skew (library-version or floating-point differences) is the hardest to catch with either approach, since the discrepancy can be too small to move a distributional metric while still compounding through a deep model; that class needs unit-level golden-value tests comparing exact outputs, not distributional monitoring.
Tell me about a time you had to get a model training or serving system to scale, but the technically best fix was too expensive, too risky, or too slow to ship. How did you align product, infra, and ML stakeholders on the tradeoff, and what was the outcome?
Sample Answer
Situation
At a previous company, our model-serving path was starting to miss peak traffic goals. The technically best fix was a larger architecture change that would have required new infra, more testing, and a long rollout.
Task
I needed to protect the launch window without taking on too much risk, while still giving product and infra a path to a better long-term solution.
Action
- I benchmarked the current system and the proposed redesign with ML, infra, and product partners.
- I framed the tradeoff in business terms: short-term SLO protection versus longer-term efficiency.
- We agreed on a two-step plan. First, ship safer improvements like batching and capacity tuning. Second, schedule the bigger rewrite for a later milestone.
- I kept everyone aligned with a simple scorecard: latency risk, engineering effort, and user impact.
Result
We met the near-term deadline without a risky rewrite, and the team bought time to design the deeper fix properly. The key lesson was that the right answer is often not the best technical answer in isolation, but the best sequence of changes for the business.
A mid-sized team is deciding whether to build training and serving on managed cloud ML services or run it themselves on Kubernetes. What would push you toward one or the other, and what would make you revisit that decision later?
Sample Answer
Direct answer
Start with managed cloud ML services unless the team already has platform engineering capacity to spare or a workload that doesn't fit managed abstractions well. The two things that should make you revisit the decision later are a computable cost crossover (your usage grows past the point where the fixed cost of running it yourselves is cheaper than the managed premium) and a hard capability wall (a hardware, scheduling, or compliance need managed can't meet).
Structured elaboration
| Criterion | Managed (e.g. a vendor's hosted training/serving service) | Self-run on Kubernetes |
|---|---|---|
| Time-to-market | Fast: built-in pipelines, autoscaling, storage/identity integrations | Slower: you build CI/CD, operators, autoscaling yourself |
| Operational overhead | Low: vendor handles patching, scheduler tuning | Real: needs dedicated platform/SRE capacity for GPU drivers, storage, networking |
| Cost predictability | Predictable billing, but a management premium is baked in and fine-grained optimization is harder | Can be cheaper at scale (spot capacity, custom bin-packing) but needs engineering effort to realize |
| Vendor lock-in | Higher: proprietary endpoint formats, registries, feature stores | Lower: standard container images and portable model formats travel across clouds |
| Custom hardware / ops | Constrained to what the vendor exposes, though many now support bring-your-own-container | Full flexibility: custom kernels, newest accelerators, custom schedulers |
Decision criteria for a mid-sized team: if the priority is fast delivery with limited dedicated ops headcount, using mostly standard frameworks, choose managed. If the priority is custom kernels, bleeding-edge hardware, strict cost control at real scale, or multi-cloud portability, choose Kubernetes. A common middle path is to start managed for experimentation and the standard model lifecycle, and move only the production-critical or genuinely specialized workloads to Kubernetes once the cost/complexity trade-off is clearly favorable, which is exactly the computation below.
Worked example
The break-even isn't a philosophical call, it's a computable crossover. Using illustrative rates (explicitly hypothetical inputs, not vendor list prices, since real prices change and shouldn't be asserted as fact) to show the shape of the calculation:
Assume the managed service charges an all-in rate of $4.00 per GPU-hour (covers autoscaling, orchestration, monitoring). Assume the raw GPU-hour cost when self-managed is $3.00, but running it yourselves requires roughly half a platform engineer's time at this scale, at a fully-loaded cost of $180,000/year:
F=12180,000×0.5=7,500 per month (fixed platform overhead)Define monthly cost as a function of GPU-hours used per month, h:
costmanaged(h)=4.00h costself(h)=3.00h+7,500Set them equal to find the crossover point:
4.00h=3.00h+7,500 h=7,500 GPU-hours/monthCheck: at h=7,500, managed costs 4.00×7,500=30,000, and self-hosted costs 3.00×7,500+7,500=22,500+7,500=30,000. They match, confirming the crossover.
Below 7,500 GPU-hours/month, managed is cheaper because the fixed platform-engineering cost isn't yet justified by volume; above it, self-hosted is cheaper. The specific number is only as good as the rates and headcount assumption you plug in, but the shape of the calculation, a fixed cost against a per-unit rate difference, is what you should actually recompute with your own numbers rather than deciding by gut feel.
Trade-offs & pitfalls
Comparing only the sticker GPU-hour price ignores engineering opportunity cost on one side and ignores real operational risk (patching, scaling failures) on the other; both belong in the model, not just the rate. Don't forget to amortize the one-time migration cost into the crossover: a move that pays off at steady state can still be a net loss for the first several months. Treat this as a decision to revisit on a schedule (say, quarterly), not a one-time fork in the road, since usage volume, team headcount cost, and vendor pricing all move independently of each other.
Your model scores noticeably better in a training notebook than it does on live traffic, even though it's the same model artifact. Walk through how you would track down where that gap is coming from.
Sample Answer
Direct answer
Since the model artifact is provably the same, the gap has to come from something upstream (the features it received) or downstream (how its output was interpreted) of the model itself. Work through a short list of candidate mismatches, isolating each with a side-by-side diff of the exact same input processed through both the notebook path and the production path, narrowing down where the two first disagree.
Structured elaboration
| Suspect | How to isolate it | Signal that confirms it |
|---|---|---|
| Preprocessing mismatch between the offline (notebook) and online transform code | Replay the same raw production inputs through the notebook's preprocessing and diff the resulting feature vectors against what the serving path actually computed | Large, systematic differences concentrated in specific columns |
| Feature retrieval or staleness (a cache returning a stale or missing value with a fallback default) | For a sample of live requests, log what the feature store actually returned versus a fresh, real-time recomputation of the same feature | Differences concentrated in cached or fallback-prone fields, not directly-computed ones |
| Encoding mismatch (categorical hashing or out-of-vocabulary handling differing between paths) | Compare encoded representations for the same raw categorical values in both stacks | Divergence only on rare or unseen categories, not the majority class |
| Numeric precision or quantization (serving running at lower precision than the notebook used for evaluation) | Run the model at the same precision used in serving against the notebook's evaluation inputs, and compare the resulting metric, not just raw output | A metric drop that appears only when precision is downgraded, concentrated in a few sensitive layers |
| Timestamp or timezone handling in temporal features | Feed identical raw timestamps through both temporal feature extractors and diff | Off-by-one-window or off-by-one-day discrepancies clustered at boundary times |
| Dependency or library version drift | Rebuild the serving environment's exact dependency versions and rerun the notebook path inside it | The gap narrows or disappears once versions match |
Instrument at the level of individual requests, not aggregate metrics: attach a checksum or signature to intermediate feature vectors and model inputs, so a diff can be run per-request rather than only comparing summary statistics across the whole traffic population.
Worked example
Use arithmetic to rule hypotheses out, not just in. If serving runs the model at 16-bit floating point precision (roughly 3 to 4 significant decimal digits) while the notebook evaluated at 32-bit precision (about 7 significant digits), a single weight can shift by roughly one representable step near its magnitude. Sixteen-bit float formats typically carry 10 explicit mantissa bits, giving a relative precision per step of about:
2−10≈0.000977
So a given weight can move by on the order of 0.1% of its magnitude purely from the precision change. If the observed gap between notebook and production is a 5-point or larger drop in area-under-curve, that is far too large to be explained by a roughly 0.1%-per-weight rounding effect alone, which lets you numerically eliminate precision as the dominant cause and redirect the search toward preprocessing or feature retrieval instead, rather than spending days chasing a plausible-sounding but arithmetically implausible explanation.
Trade-offs & pitfalls
- Assuming the gap must be in the model when the artifact is provably byte-identical wastes time; the search space is upstream and downstream of the weights, not the weights themselves.
- Debugging from aggregate metrics alone is slow; diffing at the level of individual requests narrows the search from "somewhere in the whole pipeline" to a specific stage far faster.
- Trusting a notebook re-run alone to validate a fix is risky, since the notebook environment is exactly what showed the good number in the first place; shadow-testing the fix against a slice of live production traffic is the safer check.
- Fixing the visible symptom (forcing production to match the notebook's cached value for this one feature) without understanding why the two diverged risks reintroducing the same class of bug somewhere else; the fix should target why two code paths exist for the same feature, not just patch this instance.
Design a shared ML training platform for multiple teams that need to run large distributed jobs, recover from node failures, and control cost. What core services and controls would you include, and how would jobs acquire and release compute?
Sample Answer
Core services
I would build a platform with a job API, scheduler, quota service, checkpoint store, metadata catalog, and node agents. The scheduler matches jobs to GPU pools, while the quota service enforces team budgets and priorities.
How jobs get compute
A team submits a job spec with requested GPUs, runtime, and a checkpoint policy. The scheduler grants a lease, which is a time-bounded claim on nodes. Workers heartbeat to renew the lease. On completion, failure, or preemption, the lease ends and the GPUs are released automatically.
Controls
- Per-team quotas and project budgets
- Priority classes for urgent training
- Spot first scheduling with fallback to on-demand
- Mandatory checkpoints for long jobs
- Admission control when the cluster is full
Worked example
A 64-GPU run might get 8 workers with 8 GPUs each and a 30-minute renewable lease. If a node fails, the job restarts from the last checkpoint instead of starting over.
This design keeps cost visible, failures recoverable, and shared capacity fair.
Unlock Full Question Bank
Get access to all End-to-End ML System Design interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.