Sub topic 5
Little's law: connecting concurrency, latency and throughput
This chapter assumes you know the basic request/response model, the difference between latency and throughput, and how to estimate average and peak load from earlier chapters. You should also be comfortable with simple Python arithmetic on rates and durations.
The law in one line
Little's law relates three quantities in a stable system:
in_flight = arrival_rate * time_in_system- in_flight is the average number of requests being handled at the same moment. This is the concurrency.
- arrival_rate is the average number of requests that enter per second. In a stable system it equals throughput.
- timeinsystem is the average time a request spends between entering and leaving. This includes queue time and service time.
Use consistent units. If the rate is per second, convert latency to seconds before multiplying.
The law holds for any stable system whatever the arrival pattern or service-time distribution. "Stable" means the queue is not growing without bound over the period you measure. It also holds for a single component or for a whole request path, as long as you apply it to one boundary consistently.
A worked example
Suppose a service receives 2000 requests per second at peak, and each request spends 50 ms in the system on average.
# Little's law: in_flight = arrival_rate * time_in_system
arrival_rate_per_s = 2000 # requests per second
avg_latency_ms = 50 # average time a request spends in the system
in_flight = arrival_rate_per_s * avg_latency_ms / 1000
print(in_flight) # 100.0 requests in flight on averageOn average, 100 requests are in progress at any moment. That number tells you what the service must support in parallel. A pool of 20 worker threads cannot sustain this load. The other 80 requests would wait in a queue, which raises time in the system and changes the result.
Using the law in design
You can rearrange the formula to answer different questions.
| Question | Rearranged form |
|---|---|
| How much concurrency do I need? | in_flight = arrival_rate * latency |
| What throughput can a fixed concurrency support? | arrival_rate = in_flight / latency |
| What latency can I allow at a fixed concurrency and rate? | latency = in_flight / arrival_rate |
The second form is useful for limits. A database that accepts 50 concurrent connections, with queries averaging 25 ms, can sustain at most 50 / 0.025 = 2000 queries per second. Beyond that, queries queue and latency rises.
The third form is useful for diagnosis. If a dashboard shows 400 requests in flight at 2000 requests per second, the average time in system is 400 / 2000 = 0.2 s, or 200 ms. If you expected 50 ms, something is slow or queueing.
Sizing with headroom
The average in-flight count is a starting point, not a final pool size. Real traffic fluctuates, and latency has a tail. Use peak arrival rate instead of the daily average, and add headroom so the pool is not run at 100% busy. A pool sized exactly at the average will queue often, and queueing is where tail latency grows. A later chapter on utilization covers why.
Common errors
- Mixing units. Multiplying 2000 requests per second by 50 (milliseconds) gives 100000, which is wrong by a factor of 1000.
- Using the wrong latency. The law needs the average time in system, including queue time. Using only service time under-counts concurrency when requests wait.
- Applying it to an unstable system. If arrivals exceed capacity, the queue grows, and the averages do not settle. The law gives no useful sizing answer in that case.
- Using a percentile instead of the mean. The law is exact for averages. Plugging in p99 latency gives a conservative upper estimate of concurrency, which can be useful for sizing, but it is not the average in-flight count.
- Mixing boundaries. Count the same requests on both sides. If latency is measured at the load balancer, in-flight must be counted there as well, not at the application.
Exercise
A service handles 800 requests per second at peak with an average time in system of 120 ms. Each worker handles one request at a time. How many requests are in flight on average, and what is the minimum number of workers needed? If you cap the service at 60 workers, what is the maximum throughput at the same latency?
Show answer
In flight = 800 * 0.120 = 96 requests, so you need at least 96 workers, and more for headroom. With 60 workers, maximum throughput = 60 / 0.120 = 500 requests per second.