Why loading a page takes several round trips

A round trip is a message out and the reply back. A page load needs several of them before the server runs any of your code.

You type the web address of a food delivery app into your browser and press Enter. The screen stays blank for a moment, then the page appears. The same page opens faster for some users than for others, even when the server's code takes the same time for everyone.

Your browserClient
Message out, reply backOne round trip
The app's serverServer
Think first. Your code takes 40 ms whether the user is in Katipunan or in Berlin. Why does the page still load more slowly in Berlin?
Expected answer: every setup step needs at least one round trip, and each round trip takes longer over a greater distance. Server speed does not change that. Ask students to commit to a reason before they move the slider in the next steps.

The browser completes these steps in order. Each of the first three needs at least one round trip.

  1. DNS lookup: find the server's address from its name.
  2. TCP handshake: open a connection.
  3. TLS handshake: agree on encryption.
  4. Request: send GET /courses.
  5. Server handler: your code runs.
  6. First byte: the reply starts to arrive.
More detail

The server handler is the function in your code that handles this request, and it may query the database. DNS finds the server's numeric address from its name. The TCP handshake is a short exchange of three messages. The TLS handshake takes two round trips in this model.

Press Play to watch the steps in order. Then drag the slider to the right to move the server farther away, and see which bars grow.

Idle
Browser
Server
Time spent in each step
Time to first byte —
Network distance
More detail

The numbers are illustrative. Besides your code's 40 ms and the time on the wire, each step has a small fixed processing time in the DNS server and in the handshakes.

Suppose a bigger server cuts the handler from 40 ms to 10 ms. A user in Berlin saves 30 ms. The setup steps still need about five round trips over a long distance, so most of the wait remains.

More capacity speeds up the handler step. Distance depends on where the server sits.

You can now say when a faster server helps and when only a closer one does.

More detail

Regions and failover covers choosing a location close to your users. Server capacity covers what a bigger server changes.