Sub topic 13
Sizing Replicas and Planning Capacity
Assume you know how to expose a trained model through an HTTP or gRPC endpoint. You should also be comfortable with average latency, p50 and p99 latency, basic Python, and Kubernetes Deployments. This chapter uses Little’s law, which relates request rate, latency, and the number of requests being processed.
Start with concurrency
A replica is one running copy of a model service. To estimate how many replicas you need, first estimate the number of requests that are in flight.
Little’s law is:
L = \lambda W- \(L\) is the average number of in-flight requests.
- \(\lambda\) is the arrival rate in requests per second.
- \(W\) is the average time spent processing one request, in seconds.
For example, suppose a service receives 200 requests per second and has an average latency of 120 milliseconds:
L = 200 \times 0.120 = 24The service must handle about 24 concurrent requests on average. This is not yet the replica count. You must compare this number with the useful concurrency of one replica.
If one replica can process eight requests concurrently, and you allow only 70% utilization for bursts and variation, its usable capacity is:
8 \times 0.70 = 5.6The starting estimate is therefore:
\lceil 24 / 5.6 \rceil = 5 \text{ replicas}import math
def required_replicas(
arrival_rate_rps,
avg_latency_s,
concurrency_per_replica,
target_utilization=0.7,
):
"""Estimate replicas from Little's law."""
in_flight = arrival_rate_rps * avg_latency_s
usable_concurrency = concurrency_per_replica * target_utilization
return math.ceil(in_flight / usable_concurrency)
replicas = required_replicas(200, 0.120, 8)
print(replicas) # 5Include batching in the estimate
Batching changes both throughput and latency. A larger batch may let an accelerator process more samples per second, but requests wait while the batch forms. Measure concurrency and latency with the actual batch settings rather than using a single-request benchmark.
The useful capacity of a replica depends on:
- Maximum batch size.
- Maximum queue delay.
- Input and output sizes.
- Model execution time.
- Accelerator memory.
- Whether requests have similar processing costs.
- The latency percentile required by the service objective.
A replica that handles 100 requests per second at p50 latency might handle far fewer requests while meeting a p99 objective. Capacity planning should use the highest sustained rate that keeps the required tail latency below its limit.
| Input | Example value | Why it matters |
|---|---|---|
| Arrival rate | 200 requests/s | Determines offered load |
| Average latency | 120 ms | Estimates in-flight work |
| Per-replica concurrency | 8 | Limits simultaneous requests |
| Utilization target | 70% | Leaves burst headroom |
| Estimated replicas | 5 | Initial capacity |
Validate the estimate
The formula is a planning starting point, not a capacity guarantee. Run a load test with realistic request sizes and arrival patterns. Increase load until p99 latency, queue depth, error rate, or accelerator memory crosses its limit. Record the sustainable rate per replica.
Use separate capacity numbers for different model versions or hardware types. A GPU replica and a CPU replica do not provide interchangeable capacity. Also account for unavailable replicas during deployment, node failure, or autoscaler delay. If five replicas are required for normal load, the production minimum may need to be higher to preserve service during one failure.
Exercise
A service receives 90 requests per second. Its average latency is 200 ms, each replica supports six concurrent requests, and the target utilization is 75%. What starting replica count does Little's law suggest?
Show answer
In-flight requests are 90 × 0.2 = 18. Usable concurrency per replica is 6 × 0.75 = 4.5. The estimate is ceil(18 ÷ 4.5) = 4 replicas.