Build an Internal Platform to Train, Register, and Serve ML Models
System DesignModel answerLast updated
Design an internal ML platform covering experiment tracking, a model registry, online and batch serving, and monitoring, including the API and the trade-off between containers and serverless.
Context
You are the tech lead for an internal machine learning platform at a large online retailer. Data scientists across many teams need one shared system for training models, keeping track of versions, and putting those models into production. Production use includes live, low-latency predictions as well as scheduled bulk scoring jobs.
What the platform must do
- Run tracking: Record hyperparameters, metrics, and the exact data used for each training run so any result can be reproduced later.
- Model registry: Provide one central place to store model artifacts and manage versions, including pre-release labels such as a canary build.
- Serving:
- Online inference with a tail latency target of roughly 50 ms at p99.
- High-throughput batch inference over very large datasets.
- Monitoring: Detect shifts in input data and degradation in prediction quality once models are live.
Quality attributes
- Support several frameworks (for example PyTorch, XGBoost, scikit-learn).
- Serving must be highly available and scale with demand.
- Frequent retraining means new versions must roll out with little or no downtime.
What you should deliver
- A high-level architecture, described in words or text-art.
- An API design for registering models and deploying them.
- A walkthrough of how a trained model travels from training output to serving traffic.
- A comparison of container-based microservices and serverless functions as the serving substrate, with a recommendation.
State your scale assumptions up front and call out anything you are deliberately leaving out of scope.
Hints
Hint 1
Start by fixing scale numbers (teams, models, QPS, retraining frequency) and split the 50 ms budget between feature lookup, inference, and network.
Hint 2
Decouple training from serving through an immutable artifact store plus a registry, and let a controller reconcile a declarative deployment spec instead of having training jobs push to production.
Hint 3
Think about training-serving skew: how are features computed identically offline and online, and how do you roll out safely (shadow, canary, automatic rollback) and monitor drift?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify scope and scale
I would state assumptions before drawing anything:
- About 500 data scientists, 2,000 registered models, 200 live online endpoints.
- About 1,000 training runs per day, from small CPU gradient-boosting jobs to multi-GPU deep learning.
- Peak online load around 500K QPS in aggregate (ranking, fraud, recommendations). Budget for p99 < 50 ms: roughly 10 ms feature lookup, 25 ms model compute, remainder for network and gateway.
- Batch scoring of hundreds of millions of entities daily, with occasional very large backfills.
- Retraining daily to weekly; rollouts must be zero-downtime and reversible within minutes.
- Out of scope: labeling tools, notebook environments.
2. Architecture
Flow, left to right:
- Data lake (Parquet on object storage) feeds feature pipelines (Spark for batch, Flink for streaming).
- A feature store has an offline side (point-in-time-correct history) and an online side (Redis or DynamoDB, single-digit ms reads).
- A training orchestrator (Kubernetes jobs or a managed service) reads offline features, logs to the experiment tracker, and writes an artifact to an immutable, content-addressed artifact store.
- The model registry (metadata DB plus API) records versions and pointers to artifacts.
- A deployment controller watches registry and endpoint specs and converges the cluster to the desired state.
- Online serving: gateway/router, then autoscaled model-server pods. Batch serving: Spark or Ray jobs on spot capacity writing to the warehouse.
- Every prediction is written to a prediction log (Kafka to object storage), which feeds monitoring and later becomes training data.
The key decision: training and serving meet only at the artifact store and registry. Training never deploys directly; it registers a version, and promotion is a separate, auditable step.
3. API design
POST /models/{name}/versions: body hasartifact_uri,framework,run_id, input/output schemas, feature references, preprocessing reference, metrics. Returns the new version and statusREGISTERED.POST /models/{name}/versions/{v}/transition: move toSTAGING,PRODUCTION, orARCHIVED, with an approver recorded.POST /endpoints: declarative spec with mode (online/batch), weighted traffic split (for example 95% v1.3, 5% v1.4 canary), shadow versions, resource bounds (instance type, min/max replicas, target concurrency), and a rollout policy with guardrails (p99, error rate).POST /endpoints/{name}/invoke: features or entity IDs in, prediction and model version out.POST /batch-jobs: model, version, input and output locations, schedule.POST /endpoints/{name}/rollback: target version.
Deployment is declarative: the endpoint spec is desired state and a controller converges to it. That makes canaries, rollbacks, and audits straightforward and idempotent.
4. Metadata model
runs: git SHA, container image, params, metrics, dataset snapshot ID, feature view versions.model_versions: name, version, run ID, artifact URI, SHA-256, framework, schemas, stage, creator.endpointswith versioned specs, anddeploymentswith status and timestamps.- Large blobs live in object storage; the database holds only pointers and hashes.
Reproducibility = code SHA + image + data snapshot + feature view versions + hyperparameters.
5. Training-to-production data flow
- Job reads point-in-time-correct features (prevents label leakage).
- Logs params and metrics, writes the artifact, registers a version with schemas and feature refs.
- CI gate: offline evaluation against the current production model, schema compatibility check, and a staging load test confirming p99 at target concurrency.
- On approval, the controller deploys using a generic per-framework serving image that loads the artifact at startup (avoids an image per model).
- Rollout: shadow, then 5% canary, then stepped ramp. Routing is by weight, or sticky hashing on user ID so experiments stay consistent.
- Features and predictions are logged for monitoring and future training.
6. Deep dives
Training-serving skew. Define features once and share the transform code between Spark (offline) and Flink (online). Run a skew monitor that compares logged online values with offline recomputation.
Multi-framework serving. Standardize a contract (load, predict, health) and use adapters: Triton for PyTorch/ONNX with dynamic batching (essential for GPU efficiency within the latency budget), native servers for XGBoost and sklearn. For hundreds of small models, use multi-model endpoints with lazy loading and LRU eviction.
Zero-downtime updates. Blue/green or weighted canary. Pods become ready only after the model is loaded and warmed with synthetic requests. Guardrails compare canary versus baseline on latency, errors, and prediction distribution, and automatically restore previous weights on breach.
Monitoring. Three layers: system (QPS, p50/p99, errors, GPU use), data (PSI or KS against training baseline, null rates, schema violations), and model (prediction distribution, and accuracy once delayed labels arrive). Alerts route to the owning team.
7. Containers versus serverless for serving
| Aspect | Container microservices | Serverless functions |
|---|---|---|
| Latency | Stable; warm replicas, p99 controllable | Cold starts (seconds with large models) threaten a 50 ms p99 |
| GPUs | First-class support | Limited or absent |
| Model size | Large models fine, loaded once | Package and memory limits, reload costs |
| Cost at steady high QPS | Cheaper per request | Expensive at sustained load |
| Cost at spiky or low traffic | Idle capacity unless scaled to zero | Pay per use, excellent |
| Ops burden | Cluster, autoscaling, upgrades | Minimal |
| Batching | Dynamic batching possible | Hard |
Recommendation: containers on Kubernetes for the latency-critical, high-QPS endpoints, with autoscaling on concurrency. Serverless is reasonable for rarely called, small CPU models, internal tools, and lightweight glue such as post-training validation hooks.
Common mistakes
- Letting training jobs deploy directly, which bypasses approval and auditability.
- Ignoring skew by writing feature logic twice.
- Evaluating only offline metrics and shipping without shadow or canary stages.
- Forgetting warm-up, so the first requests after a rollout blow the latency budget.
- Storing weights in the database instead of an immutable artifact store with hashes.
- Monitoring only system health and missing silent data drift.