Writing / 18 Nov 2026
The cost of a millisecond
Latency is not a number you measure once. It is a budget you spend in every layer of the path.
A millisecond sounds like a rounding error. It is not. On a quiet link it is the difference between a page that feels immediate and one that feels just slightly late. At scale, it is the difference between a service that behaves and one that develops a mysterious tail nobody can reproduce on a laptop.
The mistake is treating latency as a single number. It is a budget, and every layer of the path gets a line item.
The budget
A request does not travel from client to server. It travels through a stack of small delays, each with its own failure mode:
| Layer | Typical cost | What makes it worse |
|---|---|---|
| Propagation | ~5 µs per km of fiber, one way | Distance, detours, subsea paths |
| Serialization | ~12 µs per 1500 B at 1 Gbit/s | Slow links, small packets, overhead |
| Queueing | microseconds to seconds | Congestion, shallow buffers, bursty traffic |
| Processing | tens of µs to milliseconds | NAT, TLS, inspection, overloaded CPUs |
| Scheduling | microseconds to milliseconds | CPU contention, interrupts, noisy neighbours |
The numbers are not the point. The point is that only the first two are close to fixed. The rest are policy decisions, and most of them are invisible until something is busy.
A useful exercise is to write the budget down before optimizing anything. If the user is 40 ms away by physics and the service adds 300 ms under load, the interesting number is not the 40. It is the 300, and the queue that produced it.
Queues are where good intentions wait
A queue is not a bug. It is how a network absorbs bursts without dropping everything. The problem is that queues are easy to make deep and hard to make short.
Deep buffers feel safe: packets wait instead of being dropped, and throughput looks fine. But a packet that waits 400 ms in a buffer has already failed its job. This is the bufferbloat pattern: the link is fully utilized, the graphs are green, and the call is unusable.
The fix is not “more buffer”. It is active queue management: keep the queue short, signal congestion early, and let the transport adapt. On Linux, fq_codel and CAKE are the usual starting points. They are not magic, but they turn a standing queue into a bounded one.
# Inspect the current qdisc
tc qdisc show dev eth0
# Replace it with fq_codel (test on a lab interface first)
sudo tc qdisc replace dev eth0 root fq_codel
If you have never looked at your qdisc, do it on a link that carries real traffic. The default is not always wrong, but it is rarely chosen deliberately.
Measure the tail
Averages hide the thing users feel. A service with a 20 ms average and a 900 ms p99 is not a 20 ms service. It is a service that is occasionally terrible, which is worse than being consistently mediocre because it is harder to debug.
Measure at least:
- p50, p95, and p99 latency, per route or per flow class;
- latency under load, not just at idle;
- queue depth and drop counters on the bottleneck;
- retransmissions and round-trip time from both ends.
mtr is still one of the best first tools because it shows the path and the loss together:
mtr -rwzbc 100 203.0.113.10
For controlled experiments, tc netem lets you add delay, jitter, loss, and rate limits to a test namespace without touching production:
sudo ip netns add lab
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth1 netns lab
sudo ip netns exec lab ip link set lo up
sudo ip netns exec lab ip link set veth1 up
sudo ip link set veth0 up
sudo tc qdisc replace dev veth0 root netem delay 20ms 5ms rate 100mbit
Then measure through the namespace. Change one variable at a time. Write down what you expected before you run it. The surprise is the useful part.
One warning: latency benchmarks are easy to flatter. If you send requests sequentially and wait for each response, you never build a queue. If you send them as fast as possible, you measure the queue you created. Real traffic is somewhere in between, and it is bursty. Test with a load shape that resembles the thing you actually care about.
What I do now
- Write the budget first: physics, serialization, then policy.
- Measure p99 under realistic load, not just idle RTT.
- Treat a deep buffer as a design smell, not a safety net.
- Keep one controlled lab link with
netemfor experiments. - Record the before and after, including the command line.
The goal is not zero latency. The goal is a budget you can explain, and a tail you can defend when someone asks why the graph looks fine but the product feels slow.