01. Foundations / Lesson 1 of 3

How a Request Travels

Follow one page load from the address bar to the screen.

  • 8 min
  • Beginner
  • 9 steps
  • Total time0 ms
  • Round trips0

Address bar

https://shop.example/cart

scheme: https

host: shop.example

path: /cart

Browser
  • Request
  • Response
Step 1/9

Step 1 of 9: You press Enter. What happens now?

Read every step as text
  1. Step 1: You press Enter. What happens now?

    You type https://shop.example/cart and press Enter. A moment later a page appears. In between, your browser and several machines exchange many small messages.

    To see where the time goes, we use a made-up but realistic setup: the web server is 60 ms away by round trip (30 ms each way). We will add up every wait until the page is drawn.

    A round trip is one message out and one answer back. Most of the delay in a page load is waiting for round trips, not computing.

  2. Step 2: Step 1: turn the name into an address

    Computers reach each other by IP address, such as 203.0.113.7, not by name. The browser asks a DNS resolver (usually run by your network provider) what address shop.example has.

    If the resolver does not know, it asks other name servers on the way. We say the whole lookup takes 40 ms. The answer is cached, so the next visit skips this step.

    DNS answers carry a TTL (time to live), often minutes to hours, so most lookups never leave your device.

  3. Step 3: Step 2: open a connection, then secure it

    Before any page data moves, the browser opens a TCP connection with a handshake: hello, hello back, ready. That is one round trip, 60 ms.

    Then TLS sets up encryption, so nobody on the way can read the page. With TLS 1.3 that is one more round trip, 60 ms. Older TLS 1.2 needs two.

    Nothing useful has been sent yet, and 120 ms are gone. Reusing an open connection (keep-alive) avoids paying this again.

  4. Step 4: Step 3: the request travels to the server

    The browser sends an HTTP request over the secure connection: GET /cart, plus headers such as the cookie that says who you are.

    The request needs 30 ms to cross the network one way. The web server receives it and hands it to the app code.

  5. Step 5: Step 4: the server builds the answer

    The app code checks your session, then needs the items in your cart. It asks the database, which finds the rows in about 20 ms. The app code itself runs 10 ms.

    So the server spends 30 ms working. This is the part engineers tune most, yet it will turn out to be a small slice of the total.

    Inside the data centre the database is a short hop away, often well under 1 ms, so the query time dominates there, not the network.

  6. Step 6: Step 5: the response travels back

    The server sends back a status code (200 OK means success), headers and the page HTML. The trip home takes 30 ms.

    The request and its answer together used one more round trip (60 ms of network). That makes four round trips so far: DNS, TCP, TLS and HTTP.

  7. Step 7: Step 6: the browser draws the page

    The browser reads the HTML, builds the page and draws it. We say that takes 50 ms. Now you see the cart.

    A real page also links to images, scripts and styles. Each one is another request, which is why sites bundle files and use a CDN. We ignore them here to keep the count clean.

    Around 100 ms feels instant, and 300 ms is noticeable. Every extra file the page needs adds more waiting.

  8. Step 8: Where the time went

    Add it up: DNS 40 ms, connect 120 ms, network for the request and answer 60 ms, server 30 ms, render 50 ms. Total 300 ms.

    The network took 220 ms, which is 73% of the time. The server's own work was only 10%. Making the database twice as fast would save 10 ms; skipping the connect step on a reused connection saves 120 ms.

    To speed up a request, first remove round trips: cache DNS, reuse connections, serve from a server near the user.

  9. Step 9: A page load in one picture

    One page load used four round trips (DNS, TCP, TLS, HTTP) and took 300 ms in our setup. The network took 73% of that.

    The path is always the same: name to address, connect, secure, request, work, response, draw. Later lessons shorten it: caches skip work, CDNs shorten distance, and load balancers spread the server's job.