Skip to content

04 · THE CONNECTED PLANET

From my machine to the whole world

LOADING MODULE 04 · THE CONNECTED PLANET · CHAPTER 01/07

From my machine to the whole world

“Why does a site that opens on my computer fail to open for my friend?”

  • About 17 min read
  • LAB 04 · Publish to the world

You’ve just finished the first website of your life. It looks great on your screen and every button works. Proudly, you copy the address from the bar at the top, localhost:3000, and send it to a friend. A few seconds later your friend replies: "It won’t open."

The website isn’t broken, and your friend’s internet is fine. But between your computer and the computers of everyone else in the world, several pieces are still missing. This chapter assembles those pieces one at a time, until your website can travel out of your machine and reach the screen of someone on the other side of the planet.

The first puzzleWhy can’t my friend open it?

Look again at the address you sent. The word localhost is not your computer’s name. It’s a special word that every computer understands the same way: "this machine." The number 3000 is the where your website program is waiting for connections.

Stop and think

If localhost means "this machine," then when your friend types localhost:3000 on their own computer, which machine does their browser go to?

Try it · Who types localhost:3000?

My machinesite running on :3000emptyFriend’s machineno site runningno route between them

Pick a machine above and watch where the request goes.

The same address, typed on two different machines, gives different results
localhostThis machine
A special name that always points back to the machine you are using. Developers use it to test a website on their own machine before publishing it. Nobody outside can reach anything through this name.
Deep dive · for the extra curiousSo why don’t normal web addresses have a port number?
They always do, but it’s hidden. Sites that start with https:// use port 443, and http:// uses port 80. These are defaults every browser already knows, so you don’t have to type them. Port 3000 is simply a port many developer tools like to use for testing on your own machine.

To sum up the first puzzle: right now your website lives on your machine and nowhere else. To let other people open it, we first have to answer four questions. Where will the website live? What is the address there? How will people remember that address? And who will turn what people remember into the real address?

Piece 1A home where the lights never go out: Hosting

Your computer is switched off at night, moves to the coffee shop’s Wi-Fi, and isn’t set up to let strangers connect to it. That makes it a poor home for a website. So we send the website’s files to a server: a computer built to stay on all the time, with a fast internet connection, ready to answer anyone who asks to see the website.

HostingA home for your website
A service that rents out space on a server. The provider takes care of the power, the cooling, the internet cables and the machines. We just upload the website.

A common belief

“Websites float on "the internet" or in "the cloud," not on any particular machine.”

Deep dive · for the extra curiousWhy not just open up your computer at home to everyone?
Technically you can, but there are obstacles at every layer. Home machines usually have an internal address that only works inside the home, and the router won’t let outsiders connect in unless you set it up. Your home’s public address may keep changing. A power cut or a dropped connection takes the site down. And letting strangers reach your personal machine is a security risk. Chapter 2 explains internal and public addresses in detail.

Once the website is on a server, it has a public address made of numbers, called an IP address. In this chapter we use the example 203.0.113.10, from a range of numbers set aside for documentation and examples. It is nobody’s real machine.

IP AddressA machine’s address on the network
A set of numbers that identifies one machine on the internet, such as 203.0.113.10. Network equipment uses this number to deliver data to the right machine, like the house number on an envelope.

Pieces 2 and 3A name people can remember, and the world’s address book

At this point anyone who types 203.0.113.10 can open the website, but nobody wants to remember numbers like that. So we register a domain name such as internetmachine.example: a name you can say out loud and remember easily.

DomainDomain name
The name people use for a website instead of numbers, such as example.com. We register a name through a domain registrar and renew it from time to time, so the name stays ours as long as we keep paying the renewal fee.

But registering the name isn’t enough on its own. A freshly registered name doesn’t yet know which machine to send people to. We have to write a note in a system called DNS saying which number this name stands for.

DNS (Domain Name System)The system that translates domain names
The system that translates domain names into IP addresses. Every time we type a website’s name, the browser first asks DNS which numbered machine that name belongs to.
TEXT
Name                        Type     Value
internetmachine.example.    A        203.0.113.10
One line of DNS: an A record says which IP address this name points to

Putting it togetherWhen someone types your website’s name

Now there are enough pieces for the whole world to open the website. Let’s trace what happens in the split second after a user in Japan types internetmachine.example and presses Enter.

  1. The browser asks DNS, "Which numbered machine is internetmachine.example?" and gets the answer 203.0.113.10.
  2. The browser connects to the machine with that number and sends a request for the website’s home page. (Book 02 tells the story of requests and responses in detail.)
  3. The server replies with a response containing the HTML, CSS and JavaScript files.
  4. The browser reads those files and draws the page on the screen. (Book 01 takes this apart.)

Follow it step by step

A user in Japan types internetmachine.example

Step 1/4
  1. Browser
  2. DNS
  3. Server

Browser → DNSAsk which machine this name is

The browser doesn’t know where internetmachine.example is yet, so it first asks DNS which numbered machine the name belongs to.

Goal: Press "Next step →" until the page arrives back at the browser

Figure 1.2 · From typing a website’s name to the page on screen

Stop and think

Suppose one day you move your website to a new server with a new IP address. Do your users have to learn a new name for your website?

Hands onLab: publish your website to the world

Time to try it yourself. This lab starts with a website that lives on just one machine, the developer’s. Press the publish button and watch the pieces connect one step at a time. Notice three things: how the address bar changes, who can open the site at each step, and the routes the data takes across the map.

Skip this lab and keep reading →
EXPERIMENT · Lab 04First go one step at a time with the "Next →" button and read the explanation at every step. When you reach the Browser → Server step, scroll down to the load test. Add users until the server is overloaded, then find a fix: add servers, or turn on the CDN at the last step.
04

LAB 04 — Global Network Observatory

Publish to the world

IDLESimulation
A model for learning: the IP address, domain name, request counts, capacity and response times in this lab are made-up numbers. Use them to see trends only — they don’t predict how real servers perform.
Not securehttp://localhost:3000
localhostDeveloper’s machineThailandJapanGermanyKenyaUSABrazilDNSaddress bookNo server yet

Who can open itOnly one person can open it: the developer

Step 0 · The website still lives on the developer’s machine

The website is running at localhost:3000. The word localhost means “this machine,” so the browser on our own machine can open it. But if a friend types the same thing, their browser looks for the site on their own machine, not ours.

The command that runs the site on your own machine

$ npm run dev
> Ready at http://localhost:3000

Load test: when everyone shows up at once

Load & Capacity · made-up numbers
Right now nobody except the developer can open the site, so there is no load to test yet. Publish up to the Browser → Server step first, and this section will let you change the number of users.

If you tried everything, you probably noticed two things we haven’t explained yet: the padlock that appears at the HTTPS step, and the CDN boxes that make images load much faster for people in Brazil. The next two sections explain how they work.

Piece 4The padlock by the address: HTTPS

Between the user’s machine and the server, data passes through many devices, such as the Wi-Fi router in a coffee shop and the equipment of several internet providers. If data travels unencrypted (plain HTTP), devices along the way can read it or secretly change it, including the passwords you type.

HTTPSSecure HTTP
Sending requests and responses over an encrypted connection (using a standard called TLS). The server needs a certificate proving it really owns that domain name, and then the browser shows a padlock.

Piece 5Distance, crowds and the CDN

Data in fiber-optic cables moves very fast, about 200,000 kilometers per second, but the world is very big too. Bangkok and São Paulo in Brazil are about 16,000 kilometers apart in a straight line, so a request that has to go there and back takes at least about 160 milliseconds in theory. In practice it usually takes longer, because cables don’t run in straight lines and data passes through many devices. This waiting time is called .

A single web page is often made of dozens of files, so small delays add up until you can feel them. The fix is to put copies of files that rarely change close to users in advance.

CDN (Content Delivery Network)A network that delivers content
A network of edge servers located in many countries. It keeps copies of files such as images, CSS and JavaScript close to users. Users get those files faster, and the origin server has less work.

A CDN also helps with something just as important: load. Every server has a limited capacity: it can handle only so many requests per second. When more requests arrive than that, the extra ones have to wait in line, and when the line is full the server turns them away with the code 503 Service Unavailable, meaning "too busy to serve you right now." This is what happens to concert ticket sites the minute sales open.

  • Reduce the work that reaches the origin with a CDN, letting edges answer static files instead.
  • Add more servers and use a to split the requests among them.
  • Make each request do less work, for example by keeping results that were already calculated and reusing them. (Chapter 6 of this book goes deeper.)

Stop and think

In the lab, even with the CDN on, why can lots of users still overload the origin server?

The big pictureFour books, one machine

Look back over the whole journey. The page you see is assembled from Frontend files (Book 01). When you press a button, a request travels to the Backend to decide what happens (Book 02). Data that must be remembered is stored in a Database (Book 03). And all of it reaches you because of the Hosting, Domain, DNS, HTTPS and CDN we just put together in this chapter. Every time you open a website, this whole machine works together in less than a second.

Before we wrap up, test whether you remember which problem each piece solves.

Sort them

Which piece solves this problem?

Correct 0/6
  1. 01You switch off your computer at night, and nobody can open the website

  2. 02The website needs a public address that requests from all over the world can reach

  3. 03Nobody can remember the number 203.0.113.10

  4. 04You move the website to a new machine but want users to keep typing the same name

  5. 05A customer types a password on the coffee shop’s Wi-Fi

  6. 06People in Brazil load images from a server in Asia very slowly

Goal: Match all 6 problems with the right piece

Figure 1.3 · Which piece solves each problem?

SYSTEM SUMMARY

Chapter summary

  • 01localhost means "this machine," so a website running on our machine can be opened only by us.
  • 02Hosting means putting the website on a server that is always on and has a public IP address.
  • 03A domain is a name people can remember; DNS is the system that translates that name into an IP address.
  • 04The browser asks DNS first, then sends a request to the server and gets a response back.
  • 05HTTPS encrypts data on the way and confirms the domain name, but doesn’t guarantee the website is honest.
  • 06A CDN keeps copies of files close to users, which cuts latency and takes load off the origin server.
  • 07A server’s capacity is limited: extra work has to wait in line, or is turned away with code 503.
Skip the quiz and keep reading →

End of chapter

Check your understanding

Answered 0/4

Nothing is graded and nobody sees your answers but you. Every choice comes with an explanation — right ones and wrong ones.

Question 1

Question 1

You send a friend the link localhost:3000 and they can’t open it. What is the real reason?

Question 2

Question 2

What is the main job of DNS?

Question 3

Question 3

When you see the padlock next to a website’s name, which conclusion is correct?

Question 4

Question 4

A ticket site is about to get a huge crowd all at once. Which option directly reduces the number of requests for images and CSS files that reach the origin server?

One last step: try explaining it in your own words. Nothing reads or grades it, but putting it together yourself is the best way to find out whether you really understand.

Explain it in your own words

What you write stays on your screen. It is not sent or saved anywhere, and nothing is graded.

Write a little more (0/30 characters)

Learning path

0/4

  1. Follow a request from typing the name to the page on screen (not done yet)Figure 1.2: press "Next step →" until the last step
  2. Match all 6 problems with the piece that solves them (not done yet)Figure 1.3: pick the right piece for every problem
  3. Answer every question in the end-of-chapter quiz (not done yet)Answer them all. Wrong answers are fine and don’t affect the checkmark
  4. Explain it in your own words (not done yet)Write at least 30 characters, then press "Compare with a sample explanation"

This list records what you actually did in this browser — it is not a certificate that you understand. The best test is to explain it to someone else. You can clear the record in the Machine Lens, DATABASE tab.

NEXT DISCOVERY · End of Chapter 1

Chapter 2: Every machine has an address

IP addresses and the journey of a DNS question, from your device all the way to the root servers.

Checking access