Latency, throughput and percentiles

Topic 6 of 9 in Week 1: Foundations and the interview framework10 min readBeginnerFree course

Overview

“Make it faster” can mean several different things. A system can answer each request quickly but handle few of them, or handle huge volumes while each request takes a while. This lesson gives you the precise vocabulary, which you’ll use in requirements (“p99 under 200 ms”), estimates and trade-off discussions.

Latency, throughput and bandwidth

Three measures of fast. A pipe holds six requests in flight; latency is the time for one request from end to end, for example 80 milliseconds, and throughput is the number of requests completed per second. Bandwidth is how wide the pipe is, the maximum bits per second, while throughput is what actually flows through it. Below, concurrency versus parallelism: on one core, tasks A, B and C take turns in the order A, B, A, C, B, C; on three cores, A, B and C run at the same moment.

  • Latency is the time one request takes, from the moment it’s sent until the answer arrives. Measured in milliseconds.
  • Throughput is how many requests the system completes per unit of time, usually requests per second (RPS) or queries per second (QPS).
  • Bandwidth is the maximum amount of data a link can carry, such as 1 Gbit/s. Throughput is what you actually push through it.

These are related but separate. A truck full of hard drives driving across the country has terrible latency (days) and enormous throughput (petabytes). A chat message has tiny throughput needs but must have low latency.

Concurrency and parallelism

  • Concurrency: many tasks are in progress at the same time. A single core can be concurrent by switching between tasks whenever one waits for I/O.
  • Parallelism: tasks literally run at the same moment on different cores or machines.

Web servers rely heavily on concurrency: most requests spend their time waiting for a database or another service, so one server can keep hundreds of them in progress. CPU-heavy work, such as encoding video, needs parallelism: more cores or more machines.

Little’s Law

A simple rule connects the three ideas:

Text
requests in progress = throughput × latency

If a service handles 1,000 requests per second and each takes 0.2 seconds, about 200 requests are in progress at any moment. That number tells you how many threads, connections or memory buffers you need.

It also explains a common failure. If a database slows from 20 ms to 200 ms per query while traffic stays the same, the number of in-flight requests rises ten times. Connection pools fill up, threads run out, and the slowdown spreads to every service that calls this one. You’ll learn how to contain that in week 6.

Why averages lie: percentiles

Suppose 99 requests take 20 ms and one takes 3 seconds. The average is about 50 ms, which describes none of the requests. Instead, measure percentiles:

  • p50 (median): half the requests are faster than this. The typical experience.
  • p95: 95% are faster; 1 in 20 is slower.
  • p99: 99% are faster; 1 in 100 is slower.
  • p99.9: the extreme tail.

Requirements are written with percentiles: “p99 latency under 300 ms for the feed API”. In interviews, saying “p99” instead of “average” is a small signal that you’ve run real systems.

The tail matters more than you think

The slowest requests are not rare for your users:

  • Heavy users hit the tail most. Someone loading 100 pages a day will meet the p99 about once a day.
  • Fan-out multiplies it. If loading a page calls 10 services in parallel and waits for all of them, the page is as slow as the slowest call. With each call having a 1% chance of being slow, about 10% of pages are slow. With 100 calls, it’s 63%.

Common ways to cut tail latency include timeouts with retries, sending a backup request if the first is slow (hedged requests), avoiding long garbage-collection pauses and keeping hot data in memory.

Latency budgets

When a request passes through several components, give each a share of the target. For a 200 ms p99 target for a search page:

Step Budget
Network to the region and back 60 ms
Load balancer and gateway 5 ms
App server logic 20 ms
Search index query 80 ms
Rendering and slack 35 ms

Budgets make it obvious where to optimise and when a design can’t meet the target: if the search index alone takes 150 ms at p99, no amount of tuning elsewhere will help.

Throughput and saturation

As load on a component approaches its capacity, latency doesn’t grow evenly; it shoots up. Requests start queuing behind each other, and at about 70–80% utilisation queues grow quickly. That is why production systems keep headroom: you plan for peak traffic plus a margin, not for the average.

Recap

Latency is how long one request takes; throughput is how many finish per second; bandwidth is the size of the pipe. Concurrency keeps many requests in progress, parallelism runs them at the same time, and Little’s Law ties throughput and latency to the number in flight. Always talk about latency as percentiles, watch the tail, and remember that fan-out makes the tail everyone’s problem.

Exercise

Read the numbers

An API reports these numbers for the last hour: average latency 45 ms, p50 30 ms, p99 1,200 ms, throughput 2,000 requests per second. (a) What does the p99 tell you that the average hides? (b) Roughly how many requests per hour take longer than 1.2 seconds? (c) Using Little's Law with the average latency, about how many requests are in progress at any moment? (d) A page makes 10 of these calls in parallel and waits for all of them. Why will it often be slow?

Text
(a)
(b)
(c)
(d)

Summary

  • Latency is the time for one request; throughput is how many requests finish per second; bandwidth is the maximum data rate of a link.
  • Concurrency means many tasks in progress at once; parallelism means tasks literally running at the same moment on different cores.
  • Report latency as percentiles (p50, p95, p99); averages hide the slow tail that users notice.
  • When one request fans out to many calls, the slowest call sets the overall latency, so tail latency matters even more.
  • Little's Law: requests in progress = throughput × latency.