Learning on Web Dev Open is free for all.

System Design & Performance > Where the milliseconds goAnatomy of a request, in milliseconds
Phase 06Where the milliseconds go297 of 434

Anatomy of a request, in milliseconds

DNS, TCP, TLS, TTFB. Four costs you pay before a single byte of your page exists, and what each one responds to.

Concept15 minAI pair

Before your server does anything, the browser resolves a name, opens a connection and negotiates encryption. On a warm connection that is free; on a cold one to a new origin it is two or three round trips, which on mobile is a couple of hundred milliseconds spent before anyone has said what they want. This is why the number of distinct origins on a page is an architectural decision and not a detail.

Time to first byte then splits into travel and think. Travel you address by moving the response closer: a CDN, an edge function, a nearer region. Think you address by doing less before you emit the first byte, which usually means not querying the database in order to render the shell. Confusing the two produces the classic wasted quarter: a CDN in front of an endpoint whose 400ms is entirely server-side, gaining nothing.

Streaming is the move that changes the shape rather than the total. If the shell can be sent while the data is still being fetched, the browser starts discovering and downloading subresources during the server's think time, and the critical path overlaps instead of queueing. That is why so many recent framework features are variations on flushing early.

You should now be able to

  • Account for the time before the first byte
  • Explain why a second origin costs a round trip or two
  • Separate server think time from network time in a measurement
Ask the community

Loading…