Latency versus throughput
Understanding Little's law, response time percentiles, and tail latency amplification.
What you will learn
- Define latency and throughput, and the units each is measured in.
- Use to see how waiting grows with utilization.
- Size a pool with Little's law, and explain why p99 matters more than the average.
Precise definitions
- Latency: The elapsed time required to complete a single operation or round-trip, measured in milliseconds (ms).
- Throughput: The rate at which the system successfully processes operations or data, measured in requests per second (RPS) or bytes per second (GB/s).
You should aim for maximal throughput with acceptable latency. As utilization approaches the capacity of a server, requests spend longer waiting in its queue, and the wait grows without bound. In the simplest queueing model (M/M/1: random arrivals, one server), the average time in the system is the bare service time divided by , where is utilization:
At utilization a request takes on average its service time, at it takes , and at it takes . The growth is not exponential, but it is steep enough that systems are run well below full utilization.
Little's law of queueing
In any stable queuing system, the long-run average number of requests in the system () equals the average arrival rate () multiplied by the average time each request spends in the system ():
For example, if your application receives () and each request spends in the system (), then on average requests are in flight at once. Size thread pools and connection pools for at least that, plus headroom for bursts.
Why averages lie: tail latency (p99)
Averages obscure critical degradation. If of requests take , but take , the average looks healthy (), but in every customers experiences an unacceptable delay.
When a single user request fans out to many servers in parallel, it is only as fast as the slowest one. If a page load fans out to backend services and each independently has a chance of being slow:
Nearly of page loads are slow, even though each service is slow only of the time. Dean and Barroso's "The Tail at Scale" gives the same effect at Google: with servers per request, of user requests take over one second.
- Inbound Traffic: 1 × Clients & Users
- Reverse Proxy: 2 × Application Load Balancer
- Worker Cluster: 6 × App Compute Server
- In-Memory Cache: 2 × Redis In-Memory Cache
- Inbound Traffic sends requests to Reverse Proxy
- Reverse Proxy sends requests to Worker Cluster
- Worker Cluster sends requests to In-Memory Cache
Key takeaways
- Aim for the most throughput at acceptable latency: time in the system is the service time divided by , so 2× at 50% busy and 10× at 90%.
- Little's law, , gives the number of requests in flight; size thread and connection pools for at least that, plus headroom.
- Averages hide slow requests. A request that fans out is as slow as its slowest call: 50 calls, each slow 1% of the time, make about 40% of requests slow.
Sources
- System Design Primer: Latency vs throughput
- John D. C. Little, "Little's Law as Viewed on Its 50th Anniversary", Operations Research (2011)
- MIT OpenCourseWare 2.854: M/M/1 queue notes
- Jeffrey Dean and Luiz André Barroso, "The Tail at Scale", Communications of the ACM (2013)
Adapted from The System Design Primer by Donne Martin, licensed under CC BY 4.0. Changes were made.