Multi-Model Serving
What You'll Learn
- 1Compute replica counts and GPU memory for a fleet of models
- 2Route requests by content, user, region or experiment without adding p99 latency
- 3Run canary, shadow and A/B rollouts with automatic rollback
- 4Diagnose hot-key skew and model thrash in a shared inference server
Why This Matters
Production ML systems rarely serve a single model. They host dozens or hundreds of models - per user, per region, per task. Multi-model serving requires intelligent routing, efficient resource sharing, version management, and traffic splitting to deliver predictions reliably at scale.
Architecture Overview
Core Components
1. Model Router
The model router directs prediction requests to the appropriate model instances based on configurable routing strategies:
- Content-based routing: Routes based on request payload (e.g., language detection, input size, domain).
- User-based routing: Routes specific users to specific model versions (for personalization or A/B testing).
- Region-based routing: Routes based on geographic location for latency optimization.
- Hash-based routing: Deterministic routing based on request hash for consistent user experience.
- Round-robin routing: Cycles through healthy endpoints evenly.
- Latency-based routing: Selects the endpoint with lowest p99 latency.
The router maintains health status for each endpoint and falls back to default models when no rule matches. Endpoint health is updated based on latency and error rate monitoring.
2. Traffic Splitting
Traffic splitting manages how requests are distributed across model versions for A/B testing and canary deployments:
- Experiment creation: Define model versions with traffic percentages (must sum to 100%).
- Deterministic assignment: Users are assigned to versions based on a hash of experiment ID and user ID, ensuring consistency across requests.
- Time-bounded experiments: Experiments can have an end time after which traffic reverts to the default version.
- Metrics tracking: Monitor assignment counts and experiment status for each running experiment.
3. Ensemble Serving
Ensemble serving combines predictions from multiple models:
- Average: Simple mean of all model predictions.
- Weighted average: Each model's prediction is scaled by its importance weight.
- Voting: Majority vote for classification tasks.
- Stacking: A meta-learner combines base model predictions.
- Cascading: Returns the first non-null prediction from a priority-ordered list of models.
4. Resource Allocation
Resource management allocates GPU, CPU, and memory across the model pool:
- Allocation checks: Verifies sufficient resources before assigning models, with priority-based override for critical models.
- Deallocation: Frees resources when models are removed.
- Utilization tracking: Monitors GPU and CPU usage across the cluster.
- Scaling suggestions: Recommends replica counts based on current QPS and target QPS.
Sizing the Fleet
Replica count comes from throughput and a deliberate utilization target, because running replicas at 100 percent utilization turns every traffic spike into a p99 incident:
A replica that sustains 500 QPS with dynamic batching at batch size 32, serving 10,000 QPS at a target utilization , needs replicas. The 0.7 is the whole point: it leaves headroom for a node restart or a burst without queueing delay, which grows sharply once a server passes about 80 percent utilization.
Memory is additive across the fleet:
One hundred models averaging 1.5 GB of weights with 2 replicas each is GB, which will not fit on one 80 GB GPU node. Either raise replica count only for hot models, keep cold models on CPU, or use a serving stack with model swapping so only the working set of perhaps 15 models stays resident.
Cost per prediction is the number finance asks for:
Eight GPUs at 1.50 USD per hour for a 730 hour month cost USD. Spread over 50 million predictions that is 0.00018 USD each, or about 0.018 cents. An ensemble that runs models per request multiplies this by , so a 5-model ensemble must earn its accuracy gain: 5 times the cost is only worth it if conversion or fraud loss improves by more than that.
Failure Modes
Hot-key skew appears when one popular user or tenant pins a partition and a single replica absorbs their traffic; hash-based routing plus per-key rate limits spreads it. Thrash appears when the working set exceeds GPU memory and the server swaps models in and out on every request, so track swap count as a metric and evict by least-recently-used with a pinned hot set. Routing inconsistency appears when a user hits replicas running different versions during a rollout; stamp the model version on every response and hash the user ID together with the experiment ID so assignment is stable.
Common Mistakes
Scaling replicas until average utilization looks efficient
Fix: Target 70 percent utilization so bursts and restarts do not push p99 latency into queueing.
Loading every model into GPU memory at startup
Fix: Keep a pinned hot set resident and swap cold models with a least-recently-used policy plus a swap metric.
Letting experiment assignment depend on which replica answers
Fix: Hash experiment ID plus user ID so the same user always lands in the same arm regardless of routing.
Best Practices
- Stamp model version, experiment arm and feature version on every prediction log line
- Prefer shadow traffic over immediate A/B when a model change is large, because shadow costs only compute
- Budget ensembles explicitly: measure accuracy gain per unit of added inference cost
Key Takeaways
- Replicas follow R = ceil(QPS / (q_replica x u)); 10,000 QPS at 500 QPS and u = 0.7 needs 29 replicas
- Fleet memory is the sum of model size times replicas: 100 models at 1.5 GB with 2 replicas is 300 GB
- Cost per prediction is P_gpu x H / N_pred: 8 GPUs for a month over 50M predictions is about 0.00018 USD
- A k-model ensemble multiplies inference cost by k, so require a measured accuracy gain to pay for it
Frequently Asked Questions
How many replicas does one model need?
Use R = ceil(QPS / (q_replica x u)). Measure q_replica on the target hardware with realistic batching, not with a single-request benchmark, and set u between 0.6 and 0.8. If a replica only reaches 100 QPS because batching is disabled, the arithmetic correctly tells you that batching, not more machines, is the fix.
How do you serve 100 models without running 100 sets of replicas?
Use shared inference servers with dynamic batching and model multiplexing, keep the hot working set resident, and evict cold models under a least-recently-used policy. Scale the shared pool with horizontal pod autoscaling driven by queue depth rather than CPU, since GPU queues do not show up in CPU metrics. Reserve dedicated replicas only for the few models with strict p99 guarantees.
What is the difference between canary, shadow and A/B?
A canary sends a small real traffic fraction, typically 1 to 5 percent, to the new version and rolls back on regression. Shadow duplicates live traffic to the new version but discards its responses, so it costs compute and reveals only latency and error behavior, not business metrics. A/B splits traffic between two versions for a fixed period and measures a business metric statistically. Run shadow first for risk, then canary, then A/B when you need a causal business number.
Interview Questions
Q1: How do you implement canary deployments for ML models?
Deploy the new version alongside the old one, route 1 to 5 percent of traffic to it, and compare latency, error rate and a proxy quality metric against baseline. Increase the fraction in steps such as 1, 5, 25, 50, 100 percent, and roll back automatically when a threshold breaks. Keep a feature flag so the cutoff is instant rather than a redeploy.
Q2: What is the difference between A/B testing and a multi-armed bandit for model selection?
A/B holds the split fixed for a set duration and compares with a statistical test, which gives an unbiased estimate but spends traffic on the loser. A bandit adjusts allocation from observed rewards, wasting less traffic, at the cost of bias if assignment or timing is mishandled. Use A/B when you need a clean causal number and a bandit when optimization matters more than measurement.
Q3: Design a system serving 100 plus models with varying resource needs.
Use a model pool on shared servers such as Triton with dynamic batching, keep a hot set resident and evict cold models by LRU, scale on queue depth with Kubernetes HPA, and reserve dedicated replicas for the models with strict p99 SLAs. Track memory per model and swap count, since thrash is the failure mode that turns a healthy-looking fleet into a latency problem.