Learn

VISUAL GUIDE · FOUNDATIONS & ESTIMATION

Follow a web request

Recap

THE WHOLE PICTUREORIGINAL SKETCH
shop.example?SQL queryshort hopwarm connectionBrowserMumbaiDNS resolvercaches answersAuthoritativeDNSNearby edgealso MumbaiApp serverVirginiaDatabaseindexed, ~15 ms
A browser looks up a name through a DNS resolver, opens a connection to a distant app server that queries a database, and later goes through a nearby edge that keeps a warm connection to the server.
Recap
  1. Slow page
  2. DNS lookup
  3. TCP setup
  4. TLS setup
  5. Request sent
  6. Server work
  7. Response
  8. Reuse
  9. Nearby edge
  10. Fix the query

RECAP

What to remember

  • A first page load pays for DNS, connection setup, the request, server work and the response, in that order.
  • Distance is paid per round trip. TCP and TLS add round trips before the first byte of the request is sent.
  • A reused connection skips setup; a nearby edge shortens setup for everyone and can skip the origin for cacheable responses.
  • A slow query is server time. Only an index, a cheaper query or a cache removes it.
  • Write the breakdown before choosing a fix, then attach a number to each fix.

NOW CLOSE THE GUIDE AND REDRAW IT

On a blank page, redraw the path from browser to database for a first visit. Label each stage, then mark where a slow database query adds time and where a distant server adds time. Finally, add a nearby edge and cross out the costs it removes.

Check your drawing against this list afterwards, not before:

  • DNS lookup through a resolver, with the authoritative server only on a cache miss.
  • TCP and TLS shown as round trips to the distant server before the request.
  • Server work split into app code and the database query, with the slow query marked.
  • The response path back to the browser.
  • A nearby edge that shortens connection setup and keeps a warm connection to the origin.
  • A note on what the edge cannot fix (the uncached slow query).

APPLY IT

Sketch a weather app

GO DEEPER WITH OUR GUIDES

OFF-SITE SOURCES · NOT WRITTEN BY US

Sources and further reading

  • High Performance Browser Networking

    Ilya Grigorik (free online edition)bookFree

    Free book that explains latency, TCP, TLS and HTTP/2 from first principles. The chapters on TCP and TLS show where each round trip comes from.

  • Populating the page: how browsers work

    MDN Web DocsdocsFree

    Walks through DNS, the TCP and TLS handshakes and the first response from the browser's point of view.

  • RFC 8446: TLS 1.3

    IETFrfcFree

    The protocol spec. Section 2 gives an overview of the full handshake and why 1.3 needs one round trip before application data.

  • What is a CDN?

    Cloudflare Learning CenterarticleFree

    Short vendor explainer on how edge servers shorten distance and cache responses near users.