CAPSTONE: TRACE A REQUEST

From the browser to the database and back, and where each millisecond goes

L320 MINNETWORKING
PREDICT

RTT 40 ms, nothing reused: DNS from the resolver 50 ms, TCP 40 ms, TLS 1.3 45 ms, the request 40 ms, LB 1 ms, app 20 ms, new DB connection 15 ms, query 4 ms. Which single change saves the most on the second request?

A request is a chain of hops, and each hop has a price. DNS costs nothing from the browser cache, about 10 ms from a warm resolver, and much more when the resolver has to ask the authoritative server. A new connection costs a TCP round trip and a TLS round trip before the request leaves. Then the request round trip, the load balancer, the app, and the database. A new DB connection adds its own handshake and authentication.

Latency work is mostly about not paying setup twice: cache the name, keep the connection, resume TLS, pool the database.

▶ SIMULATION
BROWSER
DNS cache empty
connection none
TLS ticket: no · RTT to edge 40 ms
RECURSIVE RESOLVER
record cached: no (50 ms)
DNS TTL: —
EDGE · APP · DB
DB pool idle 0
budget 200 ms per request
no faults
traceno request yet
✓ every request completes within the 200 ms budget
SCHEDULE
01[OPS]config: DNS TTL 0, Connection: close, no TLS tickets, no DB pool
02[BROWSER]GET / @ 0 s
03[BROWSER]GET /api/feed @ 5 s
04[BROWSER]GET /api/cart @ 10 s
05[APP]report
Start of naive scenario. 5 steps.
browser ── DNS? ──► resolver ──► (root, TLD) ──► authoritative
   │
   ├── TCP SYN/SYN-ACK ─────► edge LB          1 RTT  (skip if keep-alive)
   ├── TLS 1.3 ─────────────► edge LB          1 RTT  (ticket: no cert work)
   ├── HTTP request ────────► edge LB ─► app   1 RTT + 1 ms
   │                                     app ─► DB pool ─► query
   ◄── first byte ───────────────────────────────────────────

new connection = DNS + 2 RTT before the request even leaves

Read the hop rows. NAIVE pays DNS, TCP, TLS and a DB connection on every request and lands at 215 ms each time. TUNED pays setup once, then 65 ms. With a CONNECTION RESET, the DNS cache and the TLS ticket keep the reconnect at 146 ms. Drag the RTT up to see when the first request stops fitting.

BREAK IT NOT YET

The tuned setup keeps every request under 200 ms. Inject one fault, at one point, that pushes a request over budget. Some faults look scary and cost almost nothing.

GOAL: a request goes over the 200 ms budget

FIX IT NOT YET

Plan the hops for one request. Return a list drawn from dns-cache, dns-resolve, tcp-connect, tls-full, tls-resume, send, lb, app, db-pool, db-connect, db-query. Use every cache that is valid at req.now, and never one that is not. caches is { dns: { [host]: { expires } }, conn: { [host]: { open } }, tickets: { [host]: { expires } }, dbIdle }.

Mental model:

latency is a sum of hops, and for small requests most of the sum is setup: name lookups and handshakes, each costing round trips. Every cache (DNS, connection, TLS ticket, DB pool) removes a term from the sum, but only while it is valid. The slow request is the one where they all miss at once.

IN PRODUCTION

Browser DevTools and the Resource Timing API split each request into DNS, connect, TLS and TTFB. Distributed tracing (OpenTelemetry) shows the server-side hops. Typical fixes: DNS TTLs in minutes rather than 0, keep-alive and HTTP/2 or HTTP/3 connection reuse, , TLS tickets, warm DB pools, and an edge close to users.

IN INTERVIEWS

“What happens when you type a URL and press Enter?”, then “the page is slow; where does the time go?” Walk the hops in order with rough costs in round trips. Then name the cache that removes each one and the event that invalidates it (TTL expiry, idle timeout, deploy, new network).

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.