map / networking / latency-budgets / interactive

Networking · interactive deep dive

What happens when you curl a URL

The principleA request’s latency is mostly a count of round trips: DNS, the TCP handshake, the TLS handshake, the request itself, and the extra rounds slow start needs — each one paying the RTT, which distance puts a hard floor under.
01

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.

curl https://example.com · one HTTPS request
DNS resolverClient (curl)ServerA? example.comA 203.0.113.7SYNSYN-ACKACK + ClientHelloServerHello … FinishedGET /200 OK (first bytes)more data (cwnd 20)more data (cwnd 40)more data (cwnd 80)TTFB 280 msdone 520 ms
Step through the request to see where each millisecond goes.
time to first byte
280 ms
total
520 ms
round trips (client↔server)
6
setup overhead
33%

Model: no packet loss, bandwidth not the limit, initial window 10 × 1460-byte segments doubling each RTT (slow start). Warm connections assume the window is already open.

02

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 time

That’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.

03

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/ms

No 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.

04

How it shows up in interviews.

The classic

“What happens when you type a URL and press Enter?” Depth beats breadth: name each round trip and what it costs.

Debugging

“This endpoint is slow only for some users.” Distance, cold connections, and DNS are the first suspects — and curl -w timing breaks them out.

Design

“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.

05

A sample question, and a strong answer dissected.

The question“Our API is hosted in one US region. Users in Australia report that the first request takes over a second, but our server-side latency is 30 ms. Explain, and tell me what you’d do.”
Measure

“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.

Model

“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.

Cheap wins

“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.

Move the edge

“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.

Verify

“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.

06

Common pitfalls.

Server-side tunnel visionServer latency excludes DNS, handshakes, and transfer — often most of what users feel.
Bandwidth thinkingFor small and medium responses, latency is set by round trips, not by link speed.
New connection per requestClients that don’t pool connections pay DNS + TCP + TLS every time.
Forgetting DNS TTLsA long TTL slows failover; a very short one turns DNS into a per-request cost.

Back to the principle

Latency budgets — the principle

Read →