Computing Foundations › How the Internet Works › Day 15
Day 15: What Happens When You Load a Web Page
After this lesson you will be able to trace, stop by stop, the journey a web request takes — URL, DNS, TCP, TLS, HTTP, server, response, render — and use that map to reason about latency, failures, and the layered structure of the internet.
Hands-on lab for this lesson
Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-015-what-happens-when-you-load-a
- Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git cd ai-roadmap-365.github.io - Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
cd labs/sections/computing-foundations/day-015-what-happens-when-you-load-a - Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
- Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
bash tests/run_tests.sh # or the test command named in the lab README
You can also open the lab as a local page (works offline, shows the file tree and expected output).
Learning objectives
By the end of this lesson you will be able to:
- List the stops of a page load in order — URL parsing, DNS lookup, TCP connection, TLS handshake, HTTP request and response, sub-resource fetching, and rendering — and say what each accomplishes
- Explain the difference between a domain name and an IP address, and why DNS is needed to bridge them
- Name the four layers of the internet protocol stack (application, transport, internet, link) and the single job each performs
- Define round-trip time and latency and explain why round trips, not bandwidth, dominate the felt speed of connection setup
- Use dig, ping, and curl to measure DNS resolution, round-trip time, and per-stage connection timings for a real site
- Read a curl timing line as a timeline and compute the cost of each stop (DNS, TCP, TLS, server) from it
- Connect the request journey to networked services: explain that every hosted-service call, dataset download, and deployed endpoint is this same pipeline
Prerequisites
- Days 1–14 of this course (the computing stack, the terminal, and running commands)
- A computer running macOS or Linux (or Windows via WSL) with an internet connection and a terminal
Why this matters
-
Every model API call is this journey. DNS, TCP, TLS, request, response — the same nine stops, every time.
-
Latency is why streaming responses exist. Waiting for a whole answer costs a round trip plus generation; streaming hides most of it.
-
“The API is slow” is usually four different things, and today you learn to tell them apart.
-
Deployment decisions are latency decisions. Which region, which edge, how many connections — all answered here.
-
This is Week 3, and it turns the network from weather into machinery.
The idea in plain language
-
Pressing Enter starts a chain of nine steps, and only one of them is the server doing your work.
-
The first four are pure setup: parse the address, look up the name, open a connection, secure it.
-
Each of those costs a round trip — the time for a signal to reach the server and come back.
-
Round trips are bounded by physics. A faster computer does not shorten them.
-
The whole design of the modern web is an attack on that number: caching, connection reuse, and moving content closer to you.
Historical background
-
The web was one request for one document, in 1991. No images, no scripts, no connection reuse.
-
HTTP/1.0 opened a new connection per resource, which made a page of thirty images cost thirty handshakes.
-
HTTP/1.1, 1997, added persistent connections — reuse the pipe, skip the handshake — and that single change is most of the era’s speed-up.
-
HTTP/2, 2015, multiplexed many requests over one connection, ending the workarounds sites had built to dodge the limit.
-
HTTP/3 moved to QUIC over UDP, folding the transport and security handshakes together to save a round trip.
-
Every version has been about the same enemy. Not bandwidth. Round trips.
What it is — and what it is not
It is:
- A chain of independent steps, each of which can fail differently.
- Mostly setup, on a first visit to a distant server.
- A layered system, where each layer treats the one below as a reliable service.
It is not:
-
Not one connection to one machine. A modern page touches a dozen hosts.
-
Not sequential after the first response. Sub-resources are fetched in parallel.
-
Not a bandwidth problem, usually. The first visit is slow because of distance, not capacity.
-
Not something the browser hides from you. Every step is visible in developer tools, which is Day 21.
Why it was created and what problems it solves
-
Names instead of numbers. DNS exists so you type
example.comrather than104.20.23.154, and so the address can change without the name changing. -
Reliability over an unreliable network. TCP turns a medium that loses and reorders packets into an ordered, complete byte stream.
-
Privacy and authenticity. TLS proves the server owns the name and stops anyone on the path reading or altering the conversation.
-
A common language. HTTP is a text protocol simple enough that you can type it by hand, which is why everything speaks it.
-
Independence between layers. Wi-Fi changed completely without HTTP noticing.
How it works
The journey, stop by stop
| # | Stop | What happens | Cost |
|---|---|---|---|
| 1 | URL parsing | Split into scheme, host and path; https defaults to port 443 | free |
| 2 | DNS lookup | Turn the name into an address | 0–1 round trips |
| 3 | TCP connection | Three-way handshake; guarantees order and completeness | 1 round trip |
| 4 | TLS handshake | Server proves it owns the name; keys agreed | 1–2 round trips |
| 5 | HTTP request | Method, path and headers — a short block of text | — |
| 6 | The server | Reads a file, runs code, queries a database | the variable part |
| 7 | HTTP response | Status line, headers, and usually HTML | — |
| 8 | Parse and fetch more | The HTML names CSS, scripts, images, fonts | often parallel |
| 9 | Render | Build the model, style, script, lay out, paint | — |
-
Stops two through four are pure setup, and on a distant connection they can outweigh the time the server spends doing the actual work.
-
Where each can fail is worth knowing: name not found at stop 2, connection refused at 3, expired certificate at 4, 404 or 500 at 6.
The layered model underneath
| Layer | Job | Example | Unit |
|---|---|---|---|
| Application | Agree what is asked and returned | HTTP, DNS, TLS | Message |
| Transport | Deliver bytes reliably to the right program | TCP, UDP | Segment |
| Internet | Address and route across networks | IP | Packet |
| Link | Move bits to the next physical device | Wi-Fi, Ethernet | Frame |
- Each layer treats the one below as a reliable service it need not understand.
- This is Day 1’s abstraction stack, applied to distance instead of silicon.
Why round trips matter
-
Round-trip time is the single most useful number in networking.
-
Signals travel near light speed, but the planet is large. Between continents, a round trip is often tens to well over a hundred milliseconds.
-
That floor cannot be optimised away by a faster computer at either end.
-
A cold HTTPS connection costs three or four round trips before the first byte of the page arrives.
-
At 100 ms RTT that is a third of a second spent purely on setup.
An everyday analogy
Ordering a book from another country.
| The order | The request |
|---|---|
| Looking up the shop’s address | DNS |
| Phoning to check they are open | TCP handshake |
| Agreeing you are talking to the real shop | TLS handshake |
| Saying which book you want | The HTTP request |
| Them finding it on a shelf | The server’s work |
| The parcel arriving | The response |
| Realising you also need the sequel | Sub-resource requests |
-
Most of the wait is the post, not the shelf. The shop found your book in seconds; the distance took days.
-
Ordering ten books at once costs one journey, not ten. That is connection reuse.
-
A local branch changes everything, which is what a content delivery network is.
Examples in practice
-
A site that is fast for you and slow overseas: nothing is wrong with the server. The distance is the cost.
-
curlreporting most of its time innamelookup: a DNS problem, not a server problem. -
A certificate error: stop 4 failing, before any request was made.
-
A page whose HTML arrives instantly and then sits blank: stop 8 — a slow or blocking sub-resource.
-
An API call that is fast on the second try: DNS and connection both cached, so three round trips vanished.
Implications: security, privacy, performance, scalability, and cost
-
Security: TLS is what makes the rest safe, and it authenticates as much as it encrypts. Without it you cannot know who answered.
-
Privacy: DNS lookups have historically been plaintext, so the names you resolve were visible even when the pages were not. Encrypted DNS is the response.
-
Performance: the fix is almost never “a faster server”. It is fewer round trips, and shorter ones.
-
Scalability: connection setup costs the server too. TLS handshakes are computationally real, which is why reuse helps both ends.
-
Cost: a content delivery network is bought to reduce distance, not capacity. That is the whole product.
-
Cost of failure varies by stop. A DNS misconfiguration takes a site down globally in a way a slow database never does.
Alternatives: free, open source, and commercial
| Tool | Type | What it shows you |
|---|---|---|
| Browser developer tools | Bundled, free | The whole waterfall, per resource |
curl -w | Free, built in | Time spent in each phase, numerically |
dig | Free, built in | Exactly what DNS returned, and from where |
ping, traceroute | Free, built in | Round-trip time and the path taken |
mtr | Free, open source | Traceroute and ping combined, continuously |
| WebPageTest | Free tier | The same page loaded from other continents |
-
curl -w '%{time_namelookup} %{time_connect} %{time_starttransfer}\n'turns “it feels slow” into four numbers you can act on. -
Test from another continent before assuming your site is fast. Yours is the least representative measurement available.
Comparison with related concepts
| Term | What it actually is |
|---|---|
| Round-trip time | Time for a signal to reach the server and return |
| Latency | Delay before transfer begins |
| Bandwidth | How much data can flow per second |
| Throughput | How much actually flowed |
| Handshake | The exchange that establishes a connection |
| CDN | Copies of content held physically closer to users |
When to use it — and when not to
-
Use this model whenever something is slow, to find out which stop is slow before changing anything.
-
Use
curl -wbefore optimising. Guessing which stage costs the time is how afternoons disappear. -
Reuse connections for anything that makes more than one request. In Python that means a session object, not a bare call.
-
Do not optimise bandwidth for a latency problem. They are different numbers with different fixes.
-
Do not measure only from your own machine, which is usually close to your server and always warm.
-
Do not disable TLS to make things faster. The saving is one round trip; the cost is everything.
The AI connection
-
Every model API call pays this cost, and a loop that opens a new connection each time pays it repeatedly for no reason.
-
Streaming responses exist because of latency. The first token arrives after one round trip rather than after the whole generation.
-
Inference region matters as much as inference speed. A model 200 ms away has a floor you cannot optimise past.
-
Batching trades latency for throughput — the same trade-off in a different costume.
-
Downloading a 10 GB model is a bandwidth problem; calling an API a thousand times is a latency problem. They need opposite fixes.
Knowledge check
quiz:
question: "An API responds in 40 ms when called from a server in the same region and 350 ms from a laptop overseas, with identical payloads. Upgrading the laptop's internet plan changes nothing. Why?"
options:
- "The extra time is round-trip latency set by distance, which bandwidth does not affect"
- "The overseas request is being throttled by the API provider's rate limits"
- "The laptop's connection has insufficient bandwidth for the response size"
- "TLS negotiation is slower on consumer hardware than on server hardware"
answer_index: 0
explanation: "The payload is identical, so capacity is not the constraint. The difference is the time a signal takes to cross the distance and come back, several times over for setup — a floor set by physics that no plan upgrade moves."
Hands-on exercise
Time each stage of a real request and find where the time goes. Worked through fully in the Day 15 lab directory.
| What you are measuring | Command |
|---|---|
| Round-trip time to a host | ping -c 5 example.com |
| What DNS returns | dig example.com +short |
| Time spent in each phase | curl -w "@curl-format.txt" -o /dev/null -s https://example.com |
| The path packets take | traceroute example.com |
| A cold connection versus a warm one | Run the curl twice and compare |
| The same site from far away | A public testing service, or a remote host |
Expected output
namelookup: 0.024s
connect: 0.061s
appconnect: 0.128s
starttransfer: 0.171s
total: 0.174s
namelookuptoconnectis one round trip — the TCP handshake.connecttoappconnectis TLS, and here it cost more than TCP did.starttransferminusappconnectis the server’s actual work: 43 ms of a 174 ms total. Setup was three quarters of it.
Validate your work
- You can name the four phases
curlreports and which stop each corresponds to - You measured a cold request and a warm one and can explain the difference
- You found a host where DNS lookup was the largest component
- You ran
tracerouteand counted the hops - You can state your round-trip time to a server on another continent
-
bash tests/run_tests.shreports 0 failures
Troubleshooting
-
pinggets no reply. Many hosts drop ICMP deliberately. Usecurltiming instead; it does not prove anything is wrong. -
tracerouteshows rows of asterisks. Routers are not obliged to answer. The path still works. -
namelookupis 0.000s. Already cached. Try a name you have not visited. -
appconnectis 0. You requestedhttp, nothttps, so there was no TLS.
Common mistakes
- Measuring once. The first request and the tenth measure different things.
- Testing only from your own location, which is the least representative one.
- Blaming the server for DNS time.
- Confusing bandwidth with latency, and buying the wrong fix.
Practice assignment
-
Time five sites on different continents and tabulate the four phases for each. Rank them by setup cost rather than total.
-
Find one site where TLS costs more than TCP, and one where it does not, and form a hypothesis about why.
-
Measure the same site cold and warm ten times each, and report the median rather than the best.
-
Draw the nine stops from memory, then check yourself against the diagram.
Extension challenge
-
Measure the connection-reuse saving. Make ten requests with a fresh connection each, then ten over one reused connection, and report the difference per request.
-
Find your own physical floor. Compute the theoretical light-speed round trip to a server you know the location of, and compare it with your measured
ping. The ratio tells you how much of the delay is distance and how much is equipment. -
Break a certificate deliberately using one of the public test sites for expired and mismatched certificates, and observe exactly which stage fails.
-
Compare HTTP/1.1 and HTTP/2 on a page with many small resources, using
curl --http1.1and--http2, and explain the difference in terms of round trips.
Quiz
Q1. You type https://example.com and press Enter. Which step happens FIRST, before the browser can request the page?
- The server renders the HTML for you
- The browser paints pixels to the screen
- The TLS handshake encrypts the page content
- The browser parses the URL and looks up the IP
Show answer
Answer: D. The browser parses the URL and looks up the IP
The browser first splits the URL into scheme, host, and path, then performs a DNS lookup to translate the host name into an IP address the network can route to. Only after there is an address can a connection be opened and the page requested.
Q2. What does the Domain Name System (DNS) actually do?
- It translates a name like example.com into an IP address
- It guarantees that packets arrive in order and complete
- It encrypts the connection so eavesdroppers cannot read it
- It renders the HTML into a visible page
Show answer
Answer: A. It translates a name like example.com into an IP address
DNS is the internet's directory: it maps memorable names to the numeric IP addresses the network routes to. Reliability is TCP's job, encryption is TLS's job, and rendering is the browser's job.
Q3. On a fresh https connection, which sequence of setup steps happens in order before the first HTTP request is sent?
- TLS handshake, then TCP connection, then DNS lookup
- DNS lookup, then TCP connection, then TLS handshake
- DNS lookup, then TLS handshake, then TCP connection
- TCP connection, then DNS lookup, then TLS handshake
Show answer
Answer: B. DNS lookup, then TCP connection, then TLS handshake
You need an address before you can connect, so DNS comes first; then TCP opens the connection to that address; then TLS negotiates encryption over that connection. Only after all three can the HTTP request go out.
Q4. Why does distance to a server matter so much for how fast a page starts to load?
- Longer distance reduces the available bandwidth to zero
- DNS cannot resolve names for far-away servers
- Each round trip takes longer, and setup needs several
- Servers far away always have slower processors
Show answer
Answer: C. Each round trip takes longer, and setup needs several
Signals travel at a finite speed, so a longer distance means a longer round-trip time. Because setting up a connection (TCP handshake, TLS handshake, DNS misses, the request itself) costs several round trips, distance multiplies the setup delay — this is latency, and a faster computer cannot remove it.
Q5. In the internet's layered model, what is the job of the transport layer (TCP)?
- To move bits over the physical Wi-Fi or Ethernet medium
- To address and route individual packets across networks
- To agree what is being asked for and returned
- To deliver an ordered, reliable byte stream to the right program
Show answer
Answer: D. To deliver an ordered, reliable byte stream to the right program
TCP (the transport layer) turns the unreliable packet delivery of IP into an ordered, complete byte stream for a specific program, retransmitting anything lost. Routing is IP's job (internet layer), moving bits is the link layer's job, and agreeing on the message format is the application layer's job.
Q6. A curl run prints: dns=0.030s connect=0.050s tls=0.100s total=0.180s. How long did the TLS handshake take?
- About 50 milliseconds
- About 100 milliseconds
- About 30 milliseconds
- About 180 milliseconds
Show answer
Answer: A. About 50 milliseconds
Each number is the elapsed time from the start at which that stage finished. TCP connect finished at 0.050s and TLS finished at 0.100s, so the TLS handshake took the gap between them: about 0.050s, or 50 milliseconds.
Q7. Your ping to a website times out with no replies, but the site loads fine in your browser. What is the most likely explanation?
- The site is down and the browser is showing a cached copy
- The server or network blocks ping (ICMP), which is separate
- DNS is broken, so the browser guessed the address
- The TLS certificate has expired
Show answer
Answer: B. The server or network blocks ping (ICMP), which is separate
Ping uses the ICMP protocol, which many servers and networks block on purpose. Web pages travel over TCP on port 443, a different path, so a blocked ping does not mean the site is down — always confirm reachability with a tool like curl.
Q8. The first response to a page load is usually just an HTML document. What does the browser do next?
- Nothing more — the single response contains the entire page
- It closes the connection and reports the page as finished
- It reads the HTML and requests the CSS, scripts, images, and fonts
- It re-runs the DNS lookup for every image individually
Show answer
Answer: C. It reads the HTML and requests the CSS, scripts, images, and fonts
The initial HTML is a skeleton that references more resources. The browser parses it, issues additional HTTP requests for the stylesheets, scripts, images, and fonts it names — usually reusing the open connection — and renders the page as those pieces arrive.
Glossary
- URL
- A Uniform Resource Locator — the full address of a resource on the web, made of a scheme (such as https), a host name, and a path, plus any query.
- DNS
- The Domain Name System, the internet's directory service that translates a human-friendly name like example.com into a numeric IP address.
- IP address
- The numeric address (such as 104.20.23.154) that identifies a machine on the network, so packets can be routed to it.
- TCP
- The Transmission Control Protocol, which delivers a reliable, ordered stream of bytes between two programs, retransmitting anything lost.
- TLS
- Transport Layer Security, the protocol that encrypts a connection and verifies the server's identity so traffic is private and tamper-proof; the S in https.
- HTTP
- The HyperText Transfer Protocol, the request-and-response format a browser and server use to ask for and return web resources.
- round-trip time
- The time for a signal to travel to the server and back again, abbreviated RTT; the basic unit of network delay.
- latency
- The delay before data begins to arrive, dominated by round-trip time and set largely by distance; distinct from bandwidth.
- bandwidth
- The amount of data a connection can carry per second; important for large transfers but not for the round trips of connection setup.
- packet
- A small, individually addressed chunk of data that the network routes independently; messages are split into packets and reassembled at the destination.
- protocol
- An agreed set of rules two computers follow to communicate, such as HTTP, TCP, IP, or TLS.
- client
- The program that initiates a request and waits for a reply, such as your web browser.
- server
- The program that listens for requests and returns responses, such as the machine hosting a website.
- encapsulation
- The layered wrapping of data as it goes down the network stack — an HTTP message inside a TCP segment inside an IP packet inside a link frame — unwrapped again at the other end.
Sources and further reading
- How the Web works — MDN Web Docs (accessed 2026-07-12) — A clear written walkthrough of the request-response pipeline covered in this lesson.
- What happens when you type a URL — High Performance Browser Networking — Ilya Grigorik (accessed 2026-07-12) — Free online book with a rigorous treatment of latency, TCP, TLS, and HTTP.
- Internet protocol suite — Wikipedia (accessed 2026-07-12) — Reference on the layered TCP/IP model used in this lesson.
- The Missing Semester of Your CS Education — MIT (accessed 2026-07-12) — Command-line tooling background for dig, curl, and friends.
- Crash Course Computer Science — The Internet — PBS Digital Studios (accessed 2026-07-12) — Short, visual explanation of packets, routing, and protocols.
Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.