map / networking / latency-budgets

Networking · principle 6 of 6

Latency budgets: what happens when you curl a URL

Light in fiber travels roughly 200 km per millisecond, so distance sets a floor on every round trip that no code can beat.

01 · Why it’s true

Signals in optical fiber travel at roughly two-thirds the speed of light in a vacuum — about 200 km per millisecond. A round trip covers the distance twice, so every 1,000 km between client and server adds at least about 10 ms of round-trip time, before any processing.

A brand-new HTTPS request needs several round trips before useful data flows: DNS (unless cached), the TCP handshake, the TLS handshake, and then the request itself. So latency is roughly the number of round trips times the round-trip time, plus server time. Removing round trips or moving closer to users usually beats optimizing code.

02 · Picture it

1DNS lookup0 RTT ifcached2TCPhandshake1 round trip3TLShandshake1 round trip(TLS 1.3)4Request1 round trip+ servertime5First byte≈ 3 RTTs +DNS laterFiber carries signals about 200 km per millisecond, so each 1,000 km adds ≥ 10 ms perround trip. Fewer round trips beats faster code.
1DNS lookup0 RTT if cached2TCP handshake1 round trip3TLS handshake1 round trip (TLS 1.3)4Request1 round trip + server time5First byte≈ 3 RTTs + DNS laterFiber carries signals about 200 km permillisecond, so each 1,000 km adds ≥10 ms per round trip. Fewer roundtrips beats faster code.
A cold HTTPS request pays for several round trips before the first byte.

03 · In the interview

  • “What happens when you type a URL and press Enter?” — answered as a sequence of round trips.
  • Explaining why a CDN or edge proxy helps users who are far away.
  • Splitting a latency target into a budget per hop in the request path.

04 · Practice question

“Our API takes 30 ms server-side, but users on another continent wait about a second for their first request. Explain.”

A strong answer covers

  1. Count round trips for a cold request: DNS, TCP handshake, TLS handshake, the request — plus a few more for a large response while TCP’s window grows.
  2. Multiply by the round-trip time for that distance; a handful of intercontinental round trips adds up to most of a second.
  3. Fixes: reuse connections, use TLS 1.3 and session resumption, shrink responses, and terminate connections at an edge close to users.
  4. Confirm with client-side timing (curl -w breaks out DNS, connect, TLS, and first byte).

Want to play with it? Open the interactive deep dive →