Your internet line is hundreds of times faster than twenty years ago, yet apps still feel slow. The reason is latency: most software is limited by how often it waits, not by how much data it moves.
For decades the answer to "it's slow" was "buy a bigger pipe". That answer has stopped working. A web app that makes thirty requests in a row feels sluggish on gigabit fibre, and a backend that runs a hundred small database queries per page is slow no matter how fast the network between the servers is. This article shows why bandwidth and latency drifted apart, where latency hides in real systems, from CPU caches to SQL queries to the browser, and what you can do about it.
It continues the networking series. Round Trips, TCP and QUIC looked at latency inside the network protocols. This article is about latency in the software we write on top of them.
1. Latency Lags Bandwidth
In 2004 David Patterson, co-inventor of RISC and RAID, published a short paper called "Latency Lags Bandwidth". He compared how much bandwidth and latency had improved over twenty to twenty-five years in four technologies: processors, memory, local networks and hard disks. The pattern was the same in all four:
- Bandwidth improved between 120x and 2,200x.
- Latency improved only between 4x and 20x.
Memory is the clearest case. DRAM modules went from 16 to 64 bits wide and got much faster clocks, so bandwidth rose about 120x. The time to fetch one random value fell only about 4x.
His rule of thumb: in the time that bandwidth doubles, latency improves by only 1.2x to 1.4x. Put differently, bandwidth improves by roughly the square of the latency improvement. If latency gets 4 times better, bandwidth gets about 16 times better.
The twenty years since then have confirmed it:
- Memory. DDR5 delivers many times the bandwidth of DDR1, but a random access to main memory still takes around 80 to 100 nanoseconds, about the same as in the early 2000s.
- Networks. Data-centre links went from 1 Gbit/s to 400 Gbit/s. The speed of light in fibre did not change: Frankfurt to New York is still about 85 ms round trip, and it always will be.
- Storage. SSDs were the one big latency win, cutting a random read from about 10 ms to under 100 microseconds. It was a one-off jump, and it is still slow compared to RAM.
Why the gap? Bandwidth can be bought with parallelism: more wires, more lanes, more channels, more fibres. Latency cannot. A signal does not arrive sooner because you send it on ten wires. Latency is limited by physics (distance and the speed of light), by fixed costs (a DRAM cell needs time to be read, a disk head needs time to move) and by the number of steps in between.
So the ratio keeps getting worse. Every year, the cost of one wait grows compared to the cost of moving one byte. Software designed when the two were roughly balanced now spends most of its time waiting.
2. The Numbers Every Engineer Should Know
The classic list "Latency numbers every programmer should know" goes back to Peter Norvig and Jeff Dean. Here is an updated version with typical values on current hardware. Exact numbers vary by machine; the orders of magnitude are what matter.
| Operation | Typical latency |
|---|---|
| L1 cache reference | 1 ns |
| L2 cache reference | 4 ns |
| L3 cache reference | 15 ns |
| Main memory (DRAM) access | 100 ns |
| Random 4 KB read from an NVMe SSD | 20–100 µs |
| Round trip within one data centre | 0.2–0.5 ms |
| Random 4 KB read from a hard disk | 5–10 ms |
| Round trip Frankfurt to Paris | 10 ms |
| Round trip Frankfurt to New York | 85 ms |
| Round trip Frankfurt to Sydney | 280 ms |
Nanoseconds are hard to feel, so scale everything up by a factor of one billion. One nanosecond becomes one second:
| Operation | Real | Scaled (1 ns = 1 s) |
|---|---|---|
| L1 cache | 1 ns | 1 second |
| DRAM | 100 ns | 1.7 minutes |
| NVMe random read | 50 µs | 14 hours |
| Data-centre round trip | 0.5 ms | 6 days |
| Hard-disk seek | 10 ms | 4 months |
| Frankfurt to New York | 85 ms | 2.7 years |
Look at that table from the point of view of a CPU. Every time your code asks another machine a question, even one in the same rack, the processor could have executed millions of instructions. Every time it asks a server on another continent, it waits the equivalent of years.
A remote call is not a slow function call. It is a different category of operation, and it should be designed like one.
3. Why More Bandwidth Doesn't Fix It
The time of any operation over a network can be approximated with one formula:
time = round trips × RTT + bytes / bandwidth + server time
Bandwidth only appears in the middle term, and for most interactive work that term is tiny. Take a typical API response of 20 KB from a server 85 ms away:
| Connection | Transfer time for 20 KB | One round trip |
|---|---|---|
| 10 Mbit/s | 16 ms | 85 ms |
| 100 Mbit/s | 1.6 ms | 85 ms |
| 1 Gbit/s | 0.16 ms | 85 ms |
| 10 Gbit/s | 0.016 ms | 85 ms |
Going from 100 Mbit/s to 10 Gbit/s saves 1.6 ms. Removing one round trip saves 85 ms, more than fifty times as much. And if the request needs five round trips in sequence, no bandwidth upgrade in the world brings it below 425 ms.
Mike Belshe measured the same effect for whole page loads at Google in 2010: above about 5 Mbit/s, more bandwidth barely improved page load time, while every reduction in RTT made pages load faster almost in proportion.
A real measurement
Here is curl loading the home page of this site, a server in a German data centre, from my desk about 25 ms away. --compressed makes curl ask for gzip like a browser does:
curl -s --compressed -o /dev/null -w \
'dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total} size=%{size_download}\n' \
https://farschidnia.de/
dns=0.0022 tcp=0.0301 tls=0.0687 ttfb=0.1072 total=0.1356 size=30583
The values are cumulative, so subtract each from the next to read the steps:
| Step | Time | What happened |
|---|---|---|
| DNS | 2 ms | Answer came from a local cache |
| TCP | 28 ms | One round trip for the handshake |
| TLS | 39 ms | One round trip for TLS 1.3, plus key exchange |
| Request until first byte | 38 ms | One round trip plus the server starting to render the page |
| Download of 30 KB | 28 ms | One more round trip: TCP slow start sends only about 14 KB before it waits for an acknowledgement |
| Total | 136 ms |
On a 100 Mbit/s line, pushing 30 KB onto the wire takes about 2.4 ms. That is the only part of the 136 ms that more bandwidth could shrink. Everything else is waiting: for handshakes, for the server, for acknowledgements.
The same request without --compressed downloads 190 KB instead of 30 KB and takes about 210 ms instead of 136 ms. The extra 75 ms are not the time to move 160 KB more data; at 100 Mbit/s that would take 13 ms. They come from the extra round trips TCP needs to grow its window, and from the server streaming the page while it renders. Compression helps here mainly because it saves round trips, not because it saves bandwidth.
4. Latency Adds Up: The Chatty Backend
The most common latency problem is not in the network. It is in the code, when a program does many small things one after another, each with a wait.
The N+1 query
You want to show 100 orders with their customer names. The tempting code with an ORM:
List<Order> orders = orderRepo.findRecent(100); // 1 query
for (Order order : orders) {
String name = order.getCustomer().getName(); // 1 query per order (lazy loading)
render(order, name);
}
This runs one query for the orders and then 100 more, one per customer: the famous N+1 problem. Each query is cheap for the database, maybe 0.1 ms of work. But each one also needs a network round trip between the application and the database:
| Setup | RTT app to DB | 101 queries | 1 query |
|---|---|---|---|
| Same host (local socket) | 0.05 ms | 5 ms | 0.05 ms |
| Same data centre | 0.5 ms | 51 ms | 0.5 ms |
| Database in another region (Frankfurt to Paris) | 10 ms | 1,010 ms | 10 ms |
The same code, the same data and the same database take 5 ms or a full second, depending only on how far away the database is. A faster link between app and database changes nothing, because each query transfers only a few hundred bytes.
The fix is to ask once:
SELECT o.id, o.total, c.name
FROM orders o
JOIN customers c ON c.id = o.customer_id
ORDER BY o.created_at DESC
LIMIT 100;
If the data lives in separate places, batch it instead:
SELECT id, name FROM customers WHERE id IN (17, 42, 108);
In JPA and Hibernate this means a JOIN FETCH, an entity graph or a batch size. The principle is the same in every stack: replace N round trips with one.
This is also why "we moved the database to the cloud and everything got slow" is such a common story. The database did not get slower. The round trips got longer, and the code had a lot of them.
Microservices make it worse
The same happens between services. A request comes in, the gateway calls the order service, which calls the customer service, which calls the database. Sequential calls add up:
client ──> gateway ──> orders ──> customers ──> database
0.5 ms 0.5 ms 0.5 ms 0.5 ms = 2 ms of pure waiting, best case
Two milliseconds sound harmless. But each hop also adds serialisation, TLS, logging, connection-pool waits and a bit of queuing, so 5 to 20 ms per hop are common in practice. Put such a call inside a loop and you are back at the N+1 problem, only now across services.
A useful exercise: draw the call graph of one user request and count the arrows that run in sequence. That number times the latency per hop is the lowest response time you can ever reach, however fast each service is.
5. Latency Adds Up: The Browser Waterfall
The frontend has the same problem with bigger round trips, because users are far away from your servers. A typical single-page app loads like this:
1. GET /index.html → finds <script src="app.js">
2. GET /app.js → runs, needs the user
3. GET /api/me → returns the user id
4. GET /api/users/42/orders → returns the order ids
5. GET /api/orders/7/items → finally, something to show
Each step needs the result of the one before. For a user in New York and a server in Frankfurt, that is at least 5 × 85 ms = 425 ms of waiting before connection setup, download or rendering. On a mobile network with 150 ms RTT it is 750 ms.
Code like this creates the waterfall:
const me = await fetch('/api/me').then(r => r.json());
const orders = await fetch(`/api/users/${me.id}/orders`).then(r => r.json());
const items = await fetch(`/api/orders/${orders[0].id}/items`).then(r => r.json());
There are three ways to break it, from cheapest to best.
Run independent requests in parallel
If two requests don't depend on each other, start them together:
// sequential: 2 round trips
const user = await fetch('/api/me').then(r => r.json());
const settings = await fetch('/api/settings').then(r => r.json());
// parallel: 1 round trip
const [user2, settings2] = await Promise.all([
fetch('/api/me').then(r => r.json()),
fetch('/api/settings').then(r => r.json()),
]);
Move the chain to the server
The server sits next to its database and services, so a chain of five calls costs 5 × 0.5 ms there instead of 5 × 85 ms from the browser. One endpoint that returns everything a page needs, often called a backend-for-frontend, turns five long round trips into one long and five short ones. Server-side rendering does the same: the HTML arrives with the data already in it.
Tell the browser early
If the browser learns about a resource only after parsing HTML and running JavaScript, it starts late. Hints in the HTML head let it start earlier:
<!-- open the connection to the API host now, before any script asks for it -->
<link rel="preconnect" href="https://api.example.com">
<!-- start loading data the app will need anyway -->
<link rel="preload" href="/api/me" as="fetch" crossorigin>
preconnect does not remove the DNS, TCP and TLS round trips for a second host, but it moves them off the critical path: they happen while the browser is still busy with the HTML. On a cold connection that is three round trips, almost half a second on a 150 ms mobile link.
6. The Tail: Why the Slowest Request Decides
So far we have looked at typical latency. In real systems the typical case is rarely the problem. The slow outliers are.
Latency is not one number but a distribution. Most requests are fast; a few are very slow because of a garbage-collection pause, a busy disk, a lost packet or a noisy neighbour on the same host. Percentiles describe this:
- p50 (median): half of the requests are faster.
- p99: 99% are faster, one in a hundred is slower.
- p99.9: one in a thousand is slower.
An average hides all of it. A service with a 20 ms average can have a p99 of 800 ms, and the average will never tell you.
Fan-out turns rare into common
In 2013 Jeff Dean and Luiz André Barroso of Google described this in "The Tail at Scale". Assume a server answers in 10 ms most of the time, but one request in a hundred takes a full second. For a single server that is acceptable: 99% of users are happy.
Now one user request fans out to 100 such servers in parallel, for example a search that asks every index shard, and waits for all answers. It is fast only if all 100 are fast:
P(all 100 fast) = 0.99 ^ 100 = 0.37
Only 37% of user requests are fast. 63% wait a full second, although each server is slow only 1% of the time.
| Parallel calls per request | Requests that hit at least one slow call |
|---|---|
| 1 | 1% |
| 10 | 10% |
| 50 | 39% |
| 100 | 63% |
| 500 | 99% |
The same applies to a page that loads 80 resources or a dashboard that calls 20 services. With enough parallel calls, your users experience your p99 on almost every page, not your p50.
What helps against the tail
- Measure percentiles, not averages. Put p50, p95 and p99 on your dashboards. If you can only have one number, take the p99.
- Reduce fan-out. Fewer calls per user request means fewer chances to hit a slow one.
- Set timeouts based on the p99 of the service you call, not on a round number. A request without a timeout can wait forever.
- Send hedged requests. If there is no answer after the p95 time, send the same request to a second replica and take whichever answers first. In a Google benchmark described in the paper (1,000 values read from 100 BigTable servers), sending the second request after just 10 ms cut the p99.9 from 1,800 ms to 74 ms, with only 2% more requests.
- Find the cause of the slow 1%. It is often a single thing: a GC pause, a cron job, a lock, a cold cache. Fixing it removes the tail for everyone.
Timeouts and retries have traps of their own; The Retry Trap covers them in detail.
7. Queues: Where Latency Explodes
One source of latency grows without any change in your code: waiting in a queue.
Every server, thread pool, connection pool, network link and disk is a queue. Requests arrive, wait for their turn and get served. When the server is nearly idle, nobody waits. When it is busy, requests queue up, and the relationship between load and waiting is not linear.
For the simplest queueing model (random arrivals, one server, called M/M/1), the average response time is:
response time = service time / (1 − utilisation)
With a service time of 10 ms:
| Utilisation | Average response time | Compared to idle |
|---|---|---|
| 10% | 11 ms | 1.1x |
| 50% | 20 ms | 2x |
| 80% | 50 ms | 5x |
| 90% | 100 ms | 10x |
| 95% | 200 ms | 20x |
| 99% | 1,000 ms | 100x |
At 90% the server does exactly the same work per request as at 50%. But the average request now waits five times as long, and the tail is far worse than the average.
This explains three things that otherwise look mysterious:
- "The server is only at 85% CPU, why is it slow?" At 85%, a request already spends almost six times its service time waiting.
- "10% more traffic doubled our latency." Going from 85% to 93% utilisation doubles the response time, from 67 ms to 143 ms in the example. Near the top of the curve, a small increase in load causes a large increase in waiting.
- Bufferbloat. A home router with a large buffer is a queue in front of a slow uplink. One big upload fills it, and every small packet behind it, a DNS lookup, a game, a video call, waits. A 1 MB buffer on a 10 Mbit/s uplink adds 800 ms of delay. A faster downlink does nothing about it.
A related rule, Little's Law, connects the three numbers of any stable queue:
requests in the system = arrival rate × time in the system
A service that handles 200 requests per second at 50 ms each has 200 × 0.05 = 10 requests in flight. If latency rises to 500 ms, there are 100 in flight, and it needs ten times as many threads, connections and memory to hold them. This is how a slow database turns into an exhausted connection pool and then into an outage: latency eats capacity.
The lesson: don't plan to run anything at 90% or more. Keep headroom, and alert on latency, not only on CPU or throughput. Throughput looks perfect right up to the moment the queue explodes.
8. The Same Rule Inside the Machine
Patterson's rule applies inside a single computer too, and the solutions look strikingly similar.
A DRAM access takes about 100 ns. A modern core runs at 4 to 5 GHz, so one cache miss costs 400 to 500 cycles, time in which it could have executed well over a thousand instructions. CPUs have large caches, prefetchers and out-of-order execution for one reason: to avoid waiting for memory.
A simple experiment shows the effect. Sum ten million numbers twice, once from an array and once from a linked list:
// array: contiguous memory, the prefetcher loads the next values before you need them
long arraySum = 0;
for (int i = 0; i < values.length; i++) arraySum += values[i];
// linked list: each node can be anywhere in memory, every step may be a cache miss
long listSum = 0;
for (Node n = head; n != null; n = n.next) listSum += n.value;
Both loops do the same number of additions. With the list nodes scattered across memory, the list loop is typically ten times slower or more. The CPU is not doing more work; it is waiting more. Each n.next is a dependency: the address of the next node is known only once the current one has arrived, so the waits cannot overlap and the prefetcher cannot guess ahead.
That is the N+1 query and the browser waterfall again, at a scale of nanoseconds instead of milliseconds:
| Level | Slow pattern | Fast pattern |
|---|---|---|
| CPU and memory | Pointer chasing (linked list) | Contiguous arrays, prefetching |
| Disk | Random reads | Sequential reads, large blocks |
| Database | N+1 queries | One JOIN or one batched IN query |
| Services | Sequential calls in a loop | Batch endpoint, parallel calls |
| Browser | Request waterfall | Parallel fetches, preload, server rendering |
The pattern is always the same: a chain of dependent waits is slow. Turn it into fewer, bigger or overlapping waits.
9. Five Ways to Beat Latency
You cannot make light faster or DRAM respond in 10 ns. But five tools work at every level:
- Do fewer round trips. Batch requests, use JOINs, combine API calls, send everything a page needs in one response. Reuse connections: an HTTP client without a connection pool pays a TCP and TLS handshake on every call.
- Shorten the distance. Put data close to users with a CDN or edge cache, and services close to their database. A service that talks to its database 50 times per request must not be 10 ms away from it.
- Overlap the waits. If you must wait for several things, wait for them at the same time:
Promise.all, async I/O, HTTP/2 multiplexing. Ten parallel calls of 85 ms take 85 ms, not 850 ms. - Don't wait at all. Cache what you have fetched before, prefetch what the user will probably need next, and use optimistic UI: show the result of a click at once and correct it if the server disagrees. The fastest request is the one you never make. More on this in Caching in Distributed Systems.
- Keep queues short. Leave capacity headroom, set timeouts and reject load early instead of queueing endlessly. A request that waits five seconds in a queue and then succeeds is often worse than one that fails fast.
10. How to Measure It
You can't fix latency you don't see. A few tools cover most cases:
pingandmtrshow the network RTT and where on the path it grows.mtrcombines ping and traceroute and shows loss per hop.curl -wwith the timing variables from section 3 splits one request into DNS, TCP, TLS, server time and download. Add--compressed, or you measure something no browser does.- Browser DevTools, Network tab. The waterfall view shows which requests wait for which; long staircases are dependency chains. The "Timing" tab of a single request splits it into DNS, connection, TLS and waiting for the server.
- The
Server-Timingheader lets the server tell the browser where it spent its time, and DevTools shows it next to the request:
Server-Timing: db;dur=42, render;dur=12, cache;desc="miss"
- Query counts and tracing. Count database queries per request: a page with 300 queries is a latency problem waiting for a slower network. Distributed tracing with OpenTelemetry shows the call graph across services and the time spent in each hop; Observability in Distributed Systems explains how to set it up.
- Percentiles everywhere. Record p50, p95 and p99. A monitoring view that shows only averages hides your worst problems from you.
11. Conclusion
Bandwidth is a solved problem for most software. It grows every year, it is cheap, and it can be bought with more parallel hardware. Latency is not solved and never will be. It is limited by distance and physics, it improves slowly, and it adds up with every dependent step your code takes.
That changes how to think about performance:
- Count waits, not bytes. The question is not "how much data do we send?" but "how often do we wait, and for how long?"
- Treat a remote call as expensive. For a CPU, a round trip to another server takes days. Design APIs and data access to need as few as possible.
- Look at the tail. With fan-out, users experience your p99, not your average.
- Watch the queues. Near full utilisation, small service times turn into long waits.
Patterson's paper quotes an old networking saying that sums it up: bandwidth problems can be cured with money, latency problems are harder, because the speed of light is fixed. Twenty years later, that is still the most useful thing to know about making software fast.
Open the Network tab of your own app and count the steps of the longest staircase. That number tells you more about its speed than any bandwidth figure.
Sources and Further Reading
- David A. Patterson, "Latency Lags Bandwidth", Communications of the ACM 47(10), October 2004.
- Jeffrey Dean and Luiz André Barroso, "The Tail at Scale", Communications of the ACM 56(2), February 2013.
- Mike Belshe, "More Bandwidth Doesn't Matter (much)", Google, 2010.
- Jeff Dean, "Latency Numbers Every Programmer Should Know", based on Peter Norvig's list in "Teach Yourself Programming in Ten Years".
- Ilya Grigorik, High Performance Browser Networking, O'Reilly, 2013, free online at https://hpbn.co
- John D. C. Little, "A Proof for the Queuing Formula: L = λW", Operations Research 9(3), 1961.
- Jim Gettys and Kathleen Nichols, "Bufferbloat: Dark Buffers in the Internet", ACM Queue 9(11), 2011.
- W3C, Server Timing: https://www.w3.org/TR/server-timing/




