map / networking / latency-budgets / interactive
Networking · interactive deep dive
What happens when you curl a URL
Step through one HTTPS request.
This is a sequence diagram: time flows downward, and each arrow is a message crossing the network. Slanted arrows take half a round trip. Drag the RTT, flip between a cold and a reused connection, and step through to see which phase owns the budget.
Latency is a count of round trips.
On a fresh connection with TLS 1.3, before the first response byte arrives you pay:
TTFB ≈ DNS + 1 RTT (TCP) + 1 RTT (TLS 1.3) + 1 RTT (request) + server timeThat’s three round trips to the server before anything useful comes back — four with TLS 1.2. Then a large response can need several more: TCP doesn’t know the path’s capacity, so it starts with a small congestion window and grows it each round trip (slow start).
Each optimization in the web stack removes round trips: keep-alive and connection pooling skip DNS, TCP, and TLS entirely; TLS 1.3 saves one RTT over 1.2; session resumption and 0-RTT shorten repeat handshakes (0-RTT data can be replayed, so it’s only safe for idempotent requests); HTTP/3 over QUIC combines the transport and TLS handshakes into one round trip.
The physics floor.
Light in optical fiber travels at roughly two-thirds of its speed 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 ~10 ms of RTT, before any routing detours, queueing, or processing.
RTTmin ≈ 2 × distance ÷ 200 km/msNo code change beats that floor. You can only remove round trips or move the endpoint closer — which is why CDNs and edge TLS termination exist: the expensive handshakes happen over a short RTT, and the long haul to the origin rides on connections that are already warm.
How it shows up in interviews.
“What happens when you type a URL and press Enter?” Depth beats breadth: name each round trip and what it costs.
“This endpoint is slow only for some users.” Distance, cold connections, and DNS are the first suspects — and curl -w timing breaks them out.
“Should we add a region or a CDN?” Show you know which part of latency is physics and which part is protocol.
A handy tool to name: curl -w "%{time_namelookup} %{time_connect} %{time_appconnect} %{time_starttransfer} %{time_total}" prints cumulative timestamps for DNS, TCP connect, TLS done, first byte, and total — this page’s phases, measured.
A sample question, and a strong answer dissected.
“I’d confirm with client-side timing — curl -w from an Australian vantage point, or real-user timing data — to split DNS, connect, TLS, first byte, and transfer. Server-side latency can’t see any of that.”
Starting from measurement, not guesses, is the first signal interviewers look for.
“Suppose the RTT is about 200 ms — plausible for that distance, since fiber alone puts the floor well over 100 ms. A cold request is DNS plus three round trips to first byte with TLS 1.3, plus a few slow-start rounds for a large response. Five or six round trips at 200 ms is over a second, and only 30 ms of it is our code.”
Turning ‘slow’ into a count of round trips makes the problem tractable.
“Make sure clients reuse connections — keep-alive, pooling, HTTP/2 or HTTP/3 — so only the first request pays setup. Enable TLS 1.3 and session resumption. Shrink and compress responses so they need fewer slow-start rounds.”
Ranking fixes by cost and impact shows judgment.
“Terminate TCP and TLS close to users with a CDN or edge proxy, so the handshakes cost a short local RTT and the edge keeps warm connections to our origin. If the API is latency-critical and data allows it, consider a region in Australia.”
Recognizing the physics floor and the architectural fix is the senior signal.
“I’d track p50 and p95 time-to-first-byte per region before and after, from the client side.”
Closing the loop with a metric shows you ship outcomes, not changes.