Design a distributed ML training infrastructure
A distributed ML training pipeline turns raw data into a validated, registered model. It's an offline batch system: ingest → preprocess → distributed train → validate → register, with experiment tracking throughout.
AI & Machine Learning, 8 components, about 40 min
1. Scope
In scope
- • Ingest + preprocess large datasets
- • Distributed training across GPUs
- • Validation + experiment tracking
- • Model registration
Out of scope
- • Online serving (separate system)
- • Data labeling tooling
- • Model architecture design
2. Functional requirements
Must have
- • Process large training datasets
- • Train across many GPU nodes
- • Track experiments + metrics
- • Register validated models
Nice to have
- • Hyperparameter search
- • Bias/fairness checks
- • Reproducibility (data + code versioning)
3. Non-functional requirements
4. Back-of-envelope estimation
Assumptions
- • Billions of training examples
- • Multi-GPU data-parallel training
- • Hourly/daily retrain cadence
- • Checkpoints to object storage
Derived numbers
5. API design
Launch a training run with data + hyperparams
Register a validated model version
6. High-level design
What each box in the reference diagram is responsible for:
7. Data model
8. Deep dives
Distributed training
Data-parallel training replicates the model across GPUs, each processing a shard of the batch, then synchronizing gradients (all-reduce). For models too large for one GPU, model/tensor parallelism splits the model itself. Kubernetes/Kubeflow schedules these multi-node jobs and handles failures/restarts from checkpoints.
Avoiding train/serve skew
Features used in training must match those served online. A shared feature store with the same definitions for offline (training) and online (serving) prevents subtle skew that silently degrades production accuracy.
Validation gates
A trained model is only promoted if it passes validation on a held-out set (accuracy thresholds) plus bias/fairness checks. This gate prevents regressions and harmful models from reaching the registry/production.
Experiment tracking & reproducibility
Every run logs hyperparameters, metrics, dataset version, and code commit (W&B/MLflow). This makes runs comparable and reproducible — essential for debugging "why did accuracy drop?" and for compliance.
9. Bottlenecks
- GPU utilization → efficient data loading, mixed precision
- Data shuffling/IO → columnar formats, sharded readers
- Cost → spot instances, checkpoint/restart
10. Trade-offs
Parallelism strategy
Choose: Data parallel (with sharded optimizer state, FSDP/ZeRO) while the model fits; add tensor and pipeline parallelism only when it does not.
Instead of: Model parallelism from the start: more communication and complexity than needed.
Data parallelism scales nearly linearly until gradient all-reduce dominates.
Checkpoint frequency
Choose: Checkpoint so expected lost work per failure is a small fraction of the interval (for example every 30–60 minutes on large jobs), asynchronously.
Instead of: Rare checkpoints: less I/O, more lost GPU-hours per failure.
At thousands of GPUs, hardware failures happen daily.
Reproducibility
Choose: Version data snapshot, code commit, config and seed in the experiment tracker.
Instead of: Ad hoc runs: fast to start, impossible to audit or reproduce.
A model you cannot reproduce cannot be debugged or compared.
11. Failure modes
GPU node fails mid-run
Whole synchronous job stops.
Mitigation: Elastic training or automatic restart from the last checkpoint with spare nodes in the pool.
Data loader bottleneck
GPUs idle at 30% utilization.
Mitigation: Pre-shuffled sharded data formats, prefetching, and enough CPU workers per GPU.
Label leakage
Great offline metrics, useless model.
Mitigation: Time-based splits and point-in-time feature joins.
12. What interviewers probe
Answer each one yourself before opening it.
How much GPU memory does a 7B-parameter model need to train?Show a strong answer
With mixed precision and Adam: ~16 bytes per parameter (weights, gradients, two optimizer moments, master weights) ≈ 112 GB before activations, so it needs sharding across GPUs.
How do you know GPUs are used well?Show a strong answer
Track model FLOPs utilization (MFU), step time breakdown (compute, communication, data), and idle time.
How do you schedule many teams' jobs on one cluster?Show a strong answer
Quotas per team, priorities with preemption, gang scheduling for multi-node jobs, and checkpointing so preemption is cheap.
When do you retrain?Show a strong answer
On a schedule matched to drift speed, or triggered by monitored drift, with automatic evaluation gates before promotion.
Sign in to track this guide in your curriculum progress.