Skip to content

Latency vs throughput

Latency is how long one operation takes. Throughput is how many operations finish per unit of time. They are linked by queueing. As throughput approaches capacity, requests start waiting for each other and latency climbs, slowly at first and then very steeply. Most performance targets come down to getting the most throughput your latency budget allows.

  • Latency — time from sending a request to receiving the response, measured where the user feels it. It includes network time, waiting in queues and the actual work. Service time is the work alone, without the waiting.
  • Throughput — completed operations per second (requests/s, messages/s, MB/s).
  • Bandwidth — the maximum rate a link or device can carry. Throughput is what you actually achieve; bandwidth is the ceiling.

A water pipe is the usual picture: latency is how long one drop takes to travel the pipe, throughput is litres per second. A long, wide pipe has high latency and high throughput. Shipping a crate of disks across a country moves petabytes per day with a latency of days. The latency numbers page lists typical costs of memory, disk and network operations.

Latency distributions are skewed: most requests are fast, and a few are very slow because of garbage collection pauses, cache misses, retries, noisy neighbours or lock waits. An average mixes the two groups into a number that describes no real request.

Take 1,000 requests: 940 take 20 ms, 45 take 80 ms, 10 take 400 ms and 5 take 2.5 s.

StatisticValueWhat it tells you
Mean38.9 msNearly twice the typical request; describes nobody
p50 (median)20 msThe typical experience
p9580 msOne request in 20 is at least this slow
p99400 msOne in 100 — a user making 100 calls per session sees it in most sessions (63%)
p99.92,500 msThe tail that timeouts and retries are built around

Practical rules:

  • Set targets on percentiles: “p99 under 300 ms for 99.9% of minutes” is something you can test.
  • Do not average percentiles across servers or time windows. The mean of ten servers’ p99 values is not the fleet’s p99. Store histograms (HDR histograms, Prometheus histograms, t-digests) and compute percentiles from the merged data.
  • Your heaviest users tend to see the tail most often, because they make the most requests and have the largest data.
  • Load generators that wait for each response before sending the next one under-report the tail. When the server stalls, they stop sending, so the stall barely shows in the results. This is called coordinated omission. Use open-model load generators that keep a fixed arrival rate.

A page often fans out to many backends in parallel, for example a search that queries 100 index shards. The response is only as fast as the slowest shard. If each server is independently slow with probability p, the chance that a request touching N servers meets at least one slow one is 1 − (1 − p)^N.

Servers touched (N)p = 1% slowp = 0.1% slow
11.0%0.1%
109.6%1.0%
10063.4%9.5%

So a backend’s p99 becomes the frontend’s median at a fan-out of about 70. Dean and Barroso’s The Tail at Scale describes how Google copes:

  • Hedged requests: send the request to a second replica if the first has not answered within, say, the p95 latency. This costs only a few percent extra load and cuts the tail sharply.
  • Tied requests: enqueue on two servers and let the first one that starts cancel the other.
  • Fewer, smaller hops: lower the fan-out, return partial results (“good enough” search), and keep slow background work off serving machines.
  • Budget per hop: give each downstream call a deadline derived from the end-to-end target, and propagate it.

For any stable system, averaged over a long enough period:

L = λ × W
L = average number of requests in the system (in flight)
λ = average arrival rate (= throughput when the system keeps up)
W = average time a request spends in the system (latency)

It holds regardless of arrival pattern or scheduling, which makes it the most useful formula in capacity planning.

Worked example. An API receives 2,000 requests/s and each request spends on average 150 ms in the service. Then L = 2,000 × 0.15 = 300 requests are in flight at any moment.

  • A worker pool of 200 threads (one request per thread) can sustain at most 200 / 0.15 ≈ 1,333 requests/s at that latency. To serve 2,000/s you need at least 300 threads plus headroom, or less time per request.
  • If each request holds a database connection for 5 ms, a pool of 40 connections caps the service at 40 / 0.005 = 8,000 queries/s.
  • Read it backwards during an incident: if in-flight requests jump from 300 to 3,000 while traffic is flat, latency has grown roughly tenfold somewhere downstream.

Queueing: why latency explodes near 100% utilisation

Section titled “Queueing: why latency explodes near 100% utilisation”

Utilisation ρ is the fraction of time a server is busy: arrival rate × service time. The classic single-server model (M/M/1: random arrivals, random service times, one worker) gives a mean response time of W = S / (1 − ρ), where S is the service time. With S = 10 ms:

Utilisation ρMean response time× service timeAvg. requests in systemApprox. p99
50%20 ms2×192 ms
80%50 ms5×4230 ms
90%100 ms10×9461 ms
95%200 ms20×19921 ms
99%1,000 ms100×994.6 s

The curve is a hockey stick. Going from 50% to 80% busy costs 30 ms on average. Going from 95% to 99% costs 800 ms. Real systems are not exactly M/M/1, but the shape holds. A pool of many workers sharing one queue stays flat for longer: with 10 workers the mean is still about 17 ms at 90% busy. It still turns sharply near 100%.

Consequences for design:

  • Keep headroom. Run latency-sensitive services at moderate average utilisation, so that peaks, failovers and noisy neighbours do not push them up the curve.
  • Variability hurts as much as load. Bursty arrivals and a mix of tiny and huge requests both lengthen queues. Isolate expensive request types in their own pools.
  • Bound every queue. An unbounded queue turns overload into minutes of latency and memory exhaustion. Reject or shed load early instead. See queues and back pressure.
  • Rising p99 is an early warning. Tail latency climbs before averages move, so alert on it.

Both techniques raise throughput by amortising fixed per-operation costs: a network round trip, a disk flush, a system call.

Batching groups many items into one operation. If a disk flush costs 2 ms, flushing every message caps a writer at 500 messages/s. Flushing batches of 100 reaches 50,000 messages/s with the same disk. The price is latency: an item may wait for the batch to fill or for a timer to fire. Kafka producers expose this trade directly as linger.ms (how long to wait for more records) and batch.size. Kafka 4.0 raised the default linger.ms from 0 to 5 ms: a few milliseconds of waiting usually buys much larger, cheaper batches.

Pipelining sends the next request without waiting for the previous response. With a 1 ms round trip, 1,000 sequential commands take at least 1 s. Pipelined, they cost roughly one round trip plus server time. This reduces latency and raises throughput, as long as each request does not depend on the previous answer. Redis pipelining, HTTP/2 and HTTP/3 multiplexing, and database protocol pipelining all apply this idea.

sequenceDiagram
  participant C as Client
  participant S as Server
  Note over C,S: Sequential: one round trip per command
  C->>S: GET a
  S-->>C: value a
  C->>S: GET b
  S-->>C: value b
  Note over C,S: Pipelined: one round trip for the batch
  C->>S: GET c
  C->>S: GET d
  S-->>C: value c
  S-->>C: value d
LeverThroughputLatencyWatch out for
Larger batchesUpUp (waiting to fill)Memory, all-or-nothing failures
Pipelining / multiplexingUpDownHead-of-line blocking, ordering assumptions
Higher utilisationUp (per dollar)Up sharply near 100%No headroom for spikes or failover
Parallel fan-outUp (work split)Tail amplifiedSlowest shard sets the pace
Hedged requestsSlightly downTail downExtra load; requests must be idempotent
CachingUpDown for hitsStaleness, cold-start misses

Based on The System Design Primer by Donne Martin (CC BY 4.0). Restructured, rewritten and updated; site content is licensed under CC BY 4.0.