Latency vs Throughput

The two most confused terms: how fast one request finishes vs how many requests the system handles at once.

Beginner5 min read
Language
Theme
Latency: time for ONE requestClient120 msServerlower is better (ms)Throughput: requests per secondhigher is better (req/sec)
Key idea at a glance

Two different currencies

Latency is how long ONE request takes, measured in milliseconds. Throughput is how MANY requests the system finishes per second. They are related but not the same: a cargo ship has huge throughput and terrible latency; a sports car is the opposite. Systems usually optimize one at the expense of the other.

The latency numbers every engineer should know

Order-of-magnitude figures (classic "Numbers Every Programmer Should Know", still accurate enough for design):

  • L1/L2 cache reference: ~1-10 ns
  • Main memory (RAM) reference: ~100 ns
  • Read 1 MB sequentially from RAM: ~0.03 ms; from SSD: ~1 ms
  • SSD random read: ~0.1 ms; HDD seek: ~10 ms
  • Round trip inside one datacenter: ~0.5 ms
  • Round trip cross-continent: ~150 ms

The one-line summary: RAM is ~1000x faster than disk; the network is slower than both. Every caching, CDN and batching decision follows from this table.

Latency: averages lie, percentiles tell the truth

An average (p50) latency of 50 ms can hide a p99 of 2 seconds: 1 in 100 users waits 2s. At scale, the tail IS the product. Why p99 blows up: one request often fans out to many internal calls; if each has a 1% chance of being slow, a request touching 100 services has a ~63% chance of hitting at least one slow call (1 - 0.99^100). Fixes: hedged/parallel requests, strict timeouts, cutting optional work at high load.

Throughput: where it caps

Throughput is set by the slowest saturated resource: CPU, DB connections, disk IOPS, or network. Example: if each request needs 10 ms of CPU on one core, one core gives 100 RPS; a 16-core server gives at most 1,600 RPS, and in practice less (context switches, GC, lock contention). This is also Little's Law in disguise: concurrency = throughput x latency. At 1,000 RPS with 100 ms average latency, ~100 requests are in flight at all times, and your thread/connection pools must be sized for it.

The classic tradeoff: batching

Processing items one by one: low latency, low throughput (every item pays fixed overhead). Batching 100 items: overhead is paid once, so throughput jumps, but items wait for the batch to fill, so latency rises. Kafka producers (linger.ms), database bulk inserts and video encoding all live on this dial.

Worked example

"Design an API at 10,000 RPS." One app server handles ~2,000 RPS of this workload, so ~6 servers plus headroom behind an LB. Average latency target 100 ms means ~1,000 concurrent requests in flight (Little's Law): set pool sizes accordingly, and set p99 budgets for each downstream call (cache 1 ms, DB 5 ms) so the total fits.

Common interview traps

  • Quoting average latency when the question is about user experience (use p95/p99).
  • Assuming latency improves by adding servers: it fixes throughput, not per-request latency. Per-request latency improves with caching, better algorithms, less work.
  • Ignoring fan-out amplification on tail latency.

Interview Q&A

Q: p99 latency doubled after traffic doubled. Why?
A: Some shared resource (DB pool, CPU, queue) crossed a saturation knee: queuing delay grows non-linearly near 100% utilization. Find the saturated resource (metrics), add capacity or cut work (cache, batch, drop optional calls), and it snaps back.

Q: How do you raise throughput without touching latency?
A: Add more parallel workers/servers behind the LB: each request still takes the same time, but more are processed concurrently.

Key takeaways

Interview pointer

For numbers questions, practice converting '1 million requests/day' into 'about 12 requests/second average, ~100/s peak'. And when discussing latency, mention p99, not the average.