From a name to a page
After this: Name the five steps of opening a page, and say which side is the client and which the server.
On this page · 4 sections · 2 checks
You type shop.example.com into a browser and press Enter. A moment later the shop's page is on your screen. In between, messages went to computers far away and came back. This tutorial follows those messages, one step at a time, and times each step.
Two sides: one asks, one answers
Every page you open is a conversation between two programs. One of them asks and the other answers.
- The is the side that asks. Here it is your browser.
- The is the side that answers. Here it is a program on the shop's computer, which waits for questions from many browsers at once.
The question is a message called a : "send me the page about product 42". The answer is a message called a : the page itself, or a note saying why there is none.
The five steps, by hand
Here is a first visit to the shop, in order.
- Find the address. The browser knows the name
shop.example.com, but the network finds machines by number, not by name. So the browser asks a directory service for the number. Lesson 2 is about that directory. - Open a connection. The browser and the server send a few messages to agree to talk, and to agree on a secret code so that nobody in between can read what follows.
- Send the request. The browser asks for the page.
- The server does its work. It often asks its database for the data, for example the product's name and price, and builds the page.
- The response comes back. The browser receives the page and draws it on the screen.
A second visit can skip the first two steps, because the browser still remembers the address and the connection may still be open. Lesson 4 times both kinds of visit.
Watch one visit
The picture below shows the browser, the directory (labelled DNS), the shop's server and its database. Press Run it and step through. Each step moves a message from one card to another and adds its time to the running total under the picture.
- 1 visitRun it and step through. Watch the request leave the browser: first to DNS for the address, then three times to the server and back, then from the server to the database. Read the running total under the picture at each step.
Press Run it, then step through and watch the requests move.
Read the steps against the list above:
- Step 2 is the lookup: the message goes to DNS and back.
- Steps 3 and 4 open the connection. Each one is a message to the server and an answer back.
- Step 5 sends the request.
- Steps 6 and 7 are the server asking its database, twice.
- Step 8 is the response: the server builds the page and sends it back.
The whole visit takes 280 ms, a little over a quarter of a second. Look at where it went. The three trips to the server and back take 80 ms each, 240 ms together. The server's part, its two questions to the database and its own work, is 20 ms. Most of the time is spent waiting for messages to travel, not on the work itself. That is the main idea of this tutorial, and lesson 4 works out each number.
Check yourself
You type the shop's name and press Enter. In what order do the steps happen?
Ana opens a shop's website on her phone. The page about a desk lamp appears. Which is the client, and which is the server?
- Name the two sides of every page you open: the client (your browser) asks, and the server answers.
- List the steps in order: find the server's address, open a connection, send the request, the server does its work, the response comes back.
- Say that a request is the message the browser sends and a response is the message the server sends back.
- Say that most of the time is spent waiting for messages to travel, not on the work itself.