Latency, Throughput & the Tail
The latency numbers worth memorizing, why p99 is the only percentile that matters, and how tail latency amplifies catastrophically as you add services.
#Two numbers people confuse
Latency is how long one operation takes. Throughput is how many operations complete per unit time. They're related but not inverse — a system can have high latency and high throughput if it's sufficiently parallel.
The pipeline analogy: a factory line where each item takes 10 minutes end to end (latency) but one item drops off the line every 5 seconds (throughput). Adding parallel lines raises throughput and leaves latency untouched.
Interviewers probe this because the fixes are different:
- Latency too high → shorten the critical path — the chain of steps a request must wait on, one after another. Cache, denormalize (store data pre-joined so one read gets everything), co-locate (put the caller and the data in the same place), remove a network hop, precompute.
- Throughput too low → add parallelism. More workers, more shards, more connections, batching.
#The latency ladder
Memorize these. They're order-of-magnitude figures, and order-of-magnitude is all you need — the point is knowing that a disk seek is ~1,000× a memory read, not the exact nanoseconds.
| Operation | Time | Human scale (×1B) |
|---|---|---|
| L1 cache reference | 1 ns | 1 second |
| Branch mispredict | 3 ns | 3 seconds |
| L2 cache reference | 4 ns | 4 seconds |
| Mutex lock/unlock | 17 ns | 17 seconds |
| Main memory reference | 100 ns | 2 minutes |
| Compress 1 KB (snappy) | 2 µs | 33 minutes |
| Read 1 MB from memory | 10 µs | 3 hours |
| SSD random read | 100 µs | 1.5 days |
| Read 1 MB from SSD | 200 µs | 3 days |
| Round trip within datacenter | 500 µs | 6 days |
| Read 1 MB from disk (HDD) | 2 ms | 23 days |
| Disk seek (HDD) | 5 ms | 58 days |
| Round trip US East ↔ US West | 60 ms | 2 years |
| Round trip US ↔ Europe | 140 ms | 4.5 years |
The right-hand column is the useful one. It makes visceral why a cross-region call inside a request path is a design decision and not an implementation detail.
Three derived facts worth having ready:
- Memory is ~1,000× faster than SSD; SSD is ~20× faster than spinning disk. This is why caching works. It's also why the working set (the data actually being read day to day) fitting in RAM is the single biggest performance cliff in database operations: the day it stops fitting, reads that took nanoseconds start taking ~100 µs.
- A same-datacenter round trip (~0.5 ms) costs more than reading 1 MB from memory. Chatty service-to-service communication is expensive: 20 sequential internal calls ≈ 10 ms of pure network before any work happens.
- The speed of light sets a floor. New York ↔ London is ~5,600 km; light in fiber does ~200,000 km/s, so ~28 ms one way, ~56 ms round trip minimum, physically. Real-world ~70–90 ms after routing. No optimization beats this — only moving the data closer does, which is the entire argument for CDNs and multi-region.
#Why averages lie
Average latency is close to useless. Consider ten requests: nine at 10 ms, one at 1,000 ms. The average is 109 ms — a number that describes no actual request. It's too slow to represent the nine fast ones and far too fast to represent the slow one.
Use percentiles instead. Sort every request by how long it took; p99 is the request 99% of the way up that list. So "p99 = 400 ms" means 99 requests in 100 finished faster than 400 ms, and one didn't.
- p50 (median) — the typical experience.
- p95 — the mild annoyance.
- p99 — the number that gets you paged.
- p999 — where your worst infrastructure behavior hides.
#Tail latency amplification
This is the concept that separates people who have operated systems from people who have read about them.
Fan-out is when one incoming request has to ask several services (or several shards) and wait for all of their answers before it can reply. Building one feed page might mean asking thirty of them.
When a request fans out to N services and must wait for all of them, the slowest one decides your latency. And as N grows, you're rolling the dice on that slow case N times per request.
If each backend has a 1% chance of exceeding 100 ms:
| Fanout N | P(at least one slow) |
|---|---|
| 1 | 1% |
| 10 | 9.6% |
| 50 | 39% |
| 100 | 63% |
At a fanout of 100, almost two thirds of your requests hit a slow backend. Think about what that does to your median (p50): more than half of all requests include at least one slow call, so your typical request is now as slow as a backend's rare 1-in-100 worst case. Your p50 is determined by your backends' p99. This is why large fanout architectures obsess over tail latency in a way that seems pathological from the outside.
Mitigations, roughly in order of usefulness:
- Hedged requests. If the first copy hasn't answered by roughly its usual worst case (p95), quietly ask a second copy as well, take whichever replies first, and cancel the other. Costs a few percent extra load, dramatically cuts the tail.
- Reduce fanout. Aggregate, batch, or precompute so one request touches fewer services.
- Return partial results. A feed that renders with 48 of 50 items beats a feed that renders at 900 ms. Requires the product to tolerate it — negotiate this in requirements.
- Timeouts with fallbacks. Every remote call needs a deadline shorter than the response time you've promised your own callers (your SLA), and a defined behavior when it fires — a cached value, a default, or a clean error.
- Tail-aware load balancing. Send each request to the server that is currently answering fastest, or has the fewest requests still waiting on it, rather than simply taking turns (round-robin). A server having a slow moment then gets less new work instead of an equal share.
#Little's Law
One formula, and it's the only queueing result you need to be able to use live. It says: the number of requests inside your system at any moment equals how fast they arrive multiplied by how long each one stays. Nothing more exotic than that — if 100 people a second walk into a shop and each stays 30 seconds, there are 3,000 people in the shop.
L = λ × W
L = concurrent requests in the system
λ = arrival rate (requests/sec)
W = average time in system (sec)It's exact and needs no assumptions about traffic patterns — it holds for any stable system, meaning one that over time finishes requests as fast as they arrive. Immediate applications:
- Sizing a thread pool. 2,000 QPS with 50 ms average service time → L = 2000 × 0.05 = 100 concurrent requests. You need ~100 workers (plus headroom). With only 20, the other 80 requests at any moment have nowhere to run, so they pile up in a queue that keeps growing until requests time out.
- Diagnosing saturation. If the number of in-flight requests is stuck at your pool size, and latency is climbing while throughput is flat, requests are spending their time waiting in line, not being worked on. Adding CPU won't help. Either make each request faster (reduce W) or allow more to run at once — a bigger pool (raise the L you can hold).
- Connection pools. Same math. A database pool of 20 with 10 ms queries supports 2,000 QPS at best, and only if nothing ever slows down.
#The saturation curve
Throughput does not rise linearly to a ceiling and plateau. It rises, flattens, and then falls:
throughput
│ ╭──────╮
│ ╭─╯ ╰──╮ ← collapse: queues grow, timeouts
│ ╭─╯ ╰───╮ fire, clients retry, load
│ ╭─╯ ╰──╮ increases, latency explodes
│╭─╯
└──────────────────────────► offered load
linear knee overloadThe knee is the point where the curve stops rising and starts bending over. Past it, a chain reaction starts. Latency grows faster than throughput, so queues build. Clients give up waiting and retry, which adds more load. Soon the servers spend their time finishing requests whose clients have already given up. This is a congestion collapse: the system is completely busy, yet almost none of that work reaches anyone. This is why you need load shedding and backpressure: a system that rejects 20% of requests quickly is strictly better than one that accepts 100% and serves none of them in time.
Rule of thumb: target ~60–70% utilization of your bottleneck resource in steady state. The remaining headroom absorbs traffic spikes, failovers, and deploys. Running at 95% "for efficiency" means the first surprise is an outage.
#What to measure
Four golden signals, and know which is which:
- Latency — p50/p99, and split successful from failed requests. Errors often return instantly, so mixing them in drags the numbers down and makes a broken service look fast.
- Traffic — QPS, concurrent connections.
- Errors — rate and class (4xx vs 5xx tell different stories).
- Saturation — how full the constrained resource is. This is the leading indicator: it climbs before anything visibly breaks, so it warns you in advance. The other three are lagging — by the time latency and errors rise, users already feel it.
#Check yourself
Latency too high versus throughput too low — how do the fixes differ?Show answer
Why is average latency close to useless?Show answer
A page makes 20 calls, each with a 1% chance of exceeding its p99. What share of page loads hit a slow call?Show answer
A request fans out to 100 backends, each slow 1% of the time. What share of requests are slow?Show answer
How do hedged requests cut tail latency, and what do they cost?Show answer
State Little's law, then use it: 5,000 requests a second at 200 ms each — how many in flight?Show answer
Why does throughput fall, not just flatten, when a system is overloaded?Show answer
Of the four golden signals, which is the leading indicator?Show answer
#What to carry forward
- Latency is how long one operation takes; throughput is how many finish per second — and they have different fixes.
- Use percentiles, not averages: p99 is what users at fan-out actually feel.
- Fan-out multiplies the tail — with 100 backends, their p99 becomes your median. Hedge, reduce fan-out, accept partial results.
- Little's law (L = λ × W) sizes pools and shows that cutting latency creates capacity.
- Keep the bottleneck at 60–70% utilisation; past the knee, throughput collapses.