Sizing a Fleet to Serve a Large Model to 100M Daily Users
System DesignModel answerLast updated
Plan an inference platform for 100M daily users: estimate traffic, memory, compute and bandwidth, pick hardware, control tail latency, and handle GPU out-of-memory failures.
You are asked to design the serving layer for a machine learning model used by 100 million daily active users. Interactive requests must be answered within a tight latency budget.
In your answer, cover the following:
- Requirements and assumptions. State which model you are sizing (type, parameter count, request shape) and the SLOs you target.
- Traffic estimate. Work from daily users to average and peak QPS, and to tokens or items per second.
- Memory budget. Account for weights, activations, caches, and the memory that batching consumes on each accelerator.
- Compute and bandwidth. Estimate FLOPs, memory bandwidth, and network needs, and turn them into a rough accelerator count.
- Hardware choice. Explain when you would use CPUs, GPUs, or specialized accelerators.
- Latency. Explain how you would reduce median and tail latency, including the batching and caching trade-offs.
- Reliability. Explain how you would prevent out-of-memory failures and recover when they happen.
Because "a model" is underspecified, begin by stating assumptions explicitly. Show your arithmetic and say how confident you are in each number.
Hints
Hint 1
Pin down the model first. A small ranking model and a multi-billion-parameter generative transformer lead to very different fleets, so fix one concrete example (parameters, layers, hidden size, tokens in and out) before doing any math.
Hint 2
Do two separate estimates for the accelerator count: one limited by compute (FLOPs per token times tokens per second) and one limited by memory bandwidth during token-by-token decoding. Then check what actually caps the batch size per GPU; it is often the per-sequence cache, not compute.
Hint 3
For tail latency and OOM, think about admission control and scheduling: cap context and output length, reserve memory by blocks, route by free cache capacity rather than round-robin, and decide in advance what gets preempted or shed when memory runs out.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Pin down the workload
I would first ask about model type, latency target, request shape, and availability/cost limits. For the rest of the answer I assume a 13B-parameter decoder-only transformer (40 layers, hidden size 5120) in an interactive product:
- Time to first token (TTFT) p99 under 500 ms
- Time per output token (TPOT) p99 under 50 ms
- 99.9% availability
- About 500 prompt tokens and 200 generated tokens per request
A single-pass model such as a ranker or embedder would be far cheaper, and I come back to that at the end.
2. Traffic
- 100M users × ~10 requests/day = 1B requests/day
- Average: 1B / 86,400 ≈ 11.6K QPS
- Peak at about 3× average: ~35K QPS
- Prefill: 35K × 500 ≈ 17.5M tokens/s
- Decode: 35K × 200 ≈ 7M tokens/s
I provision for peak plus the loss of one region. Each region therefore runs at about 60–70% of capacity at peak, so survivors can absorb a failed neighbor.
3. Memory per GPU (80 GB card)
- Weights: 13B × 2 bytes in BF16 = 26 GB. INT8 gives 13 GB and INT4 about 7 GB.
- KV cache: per token = 2 (K and V) × 40 layers × 5120 × 2 bytes ≈ 0.8 MB. A 2K-token sequence takes about 1.6 GB. Grouped-query attention with 8 KV heads instead of 40 cuts this 5× to about 0.33 GB.
- Activations: transient, and they scale with tokens per step rather than context length. A few GB covers chunked prefill of 2–4K tokens.
- Runtime overhead: CUDA context, allocator fragmentation and communication buffers take about 4–6 GB.
That leaves roughly 80 − 26 − 6 ≈ 48 GB for cache. This holds about 30 concurrent 2K sequences with full multi-head attention, or about 145 with GQA.
Batch size is limited by cache memory, not by compute. The best levers are paged KV allocation, FP8 or INT8 cache, GQA, and shorter context caps.
4. Compute, bandwidth, and fleet size
Compute. One token costs about 2 × params = 26 GFLOPs. At 24.5M tokens/s the peak demand is about 640 PFLOP/s. An H100 gives roughly 990 dense BF16 TFLOPS, and at about 40% utilization we get ~400 TFLOPS. That implies ~1,600 GPUs if compute were the only limit.
Decode bandwidth. Each decode step reads all 26 GB of weights from HBM. At 3.35 TB/s, a step takes at least ~8 ms, or ~125 steps/s per GPU. Batching amortizes the weight read, so a batch of 64 gives about 8K tokens/s per GPU. For 7M decode tokens/s that is about 900 GPUs, before counting the cache reads. Prefill is compute bound and decode is bandwidth bound, which is why many systems separate the two pools.
Fleet. With headroom and regional failover, I would estimate 2,000–3,000 H100-class GPUs in total. I would say clearly that this is a first-order estimate and that profiling on the real request mix would refine it.
Network.
- Client traffic is small: ~3 KB per request × 35K QPS ≈ 100 MB/s, and streamed output is similar.
- Tensor parallelism (for example TP=2) adds all-reduce traffic of about 10 KB per token per collective, which NVLink (~900 GB/s) handles easily. Keep TP inside one node, and use pipeline parallelism across nodes only if the model cannot fit in one node.
- Cold start is a bandwidth issue. Loading 26 GB at about 3 GB/s takes roughly 9 s, and loading from object storage is slower. Keep weights on local NVMe and a warm pool of spare replicas.
5. Architecture
- Global load balancer routes by geography and region health.
- Gateway handles auth, per-tenant rate limits, and validation, including caps on prompt length and
max_new_tokens. - Router sends each request to the replica with the most free KV capacity, not round-robin. It also uses prefix affinity so that shared system prompts hit a prefix cache.
- Model servers run an engine in the style of vLLM or TensorRT-LLM, with continuous batching and a paged KV cache. Prefill and decode may run on separate pools.
- Autoscaler scales on queue depth, KV utilization and TTFT rather than CPU, and pre-scales ahead of the known daily peak.
- Rollout goes through shadow traffic, then a 1% canary, then progressive rollout with automatic rollback on latency or quality regressions.
6. CPU vs GPU vs accelerator
- CPU: small models (under ~100M parameters), tree ensembles, sparse embedding lookups. Low, predictable latency at small batches and cheap horizontal scaling. Also used for tokenization, routing and preprocessing.
- GPU: the default for large dense and transformer models, thanks to HBM bandwidth and a mature software stack.
- TPU, Inferentia and other ASICs: better cost and energy per token for stable, high-volume models, but with more engineering effort, lock-in, and slower support for new operators.
I would decide by benchmarking on the real request distribution at the target p99 and comparing cost per million tokens, not peak FLOPS.
7. Latency and tail latency
- Continuous batching: finished sequences leave and new ones join every step, so short requests do not wait on long ones.
- Chunked prefill: long prompts are split so they do not stall decoding for other users, which protects TPOT.
- Quantization and fused attention kernels: these cut bytes moved per token.
- Speculative decoding: a small draft model proposes tokens that the large model verifies, which reduces TPOT at low to moderate load.
- Prefix caching: reuse the cache for shared prompt prefixes to lower TTFT.
- Tail control: use priority queues and deadlines, cap output length, and shed or degrade load early (for example, route to a smaller model) rather than letting queues grow. Hedged requests help only when the extra load is small, because duplicates add load exactly when the system is busy.
- Trade-off: larger batches improve throughput and cost but raise per-token latency. Set the batch limit from the p99 SLO, not from peak throughput.
8. Preventing and recovering from OOM
Prevention
- Allocate the KV cache in fixed-size blocks from a preallocated pool, so memory use is known and fragmentation is limited.
- Use admission control. Admit a request only if its worst-case blocks (prompt plus
max_new_tokens) fit, or use an optimistic policy with preemption as backup. - Cap context and output lengths at the gateway, and cap the tokens per step.
- Leave a memory headroom of about 5–10%, and alert when KV utilization stays above ~85–90%.
Recovery
- If the pool runs out, preempt the lowest-priority or most recently admitted sequences. Either swap their blocks to host memory or drop them and recompute the prefill later.
- Return a retryable error with backoff when a request cannot be placed, and have the router stop sending traffic to a replica near its limit.
- If a process does crash, health checks remove it from rotation, the orchestrator restarts it from local NVMe, and in-flight streams are retried on another replica. Making requests idempotent through a
request_idhelps here. - Track preemption rate and OOM restarts as first-class metrics, and treat a rising rate as a signal to add capacity or tighten limits.
9. Common mistakes
- Sizing for average QPS and forgetting peak and failover.
- Treating GPUs as compute-bound during decode, and missing that the KV cache sets the batch size.
- Using round-robin routing and scaling on CPU utilization.
- Giving one number without stating assumptions or how to validate them.
10. If the model is small
For a ranker of tens of millions of parameters, weights and cache are tiny. The problem becomes CPU or small-GPU serving with large dynamic batches, feature fetch latency and cache hit rate. The fleet shrinks by one to two orders of magnitude, and tail latency is driven by feature stores and fan-out rather than by memory.