Interactive Guide

How the web works
from localhost to CDN

Everything we covered — local servers, HTTP, headers, caching, origins, ports, CDNs, and DNS — in one place you can click through and explore.

What is a server? HTTP request lifecycle Headers Same-origin policy Ports Cache-Control CDN cache DNS
Chapter 01

What does "server" actually mean?

The word server is doing double duty. It refers to a physical machine and to a piece of software. Most confusion comes from mixing those two up.

Server as hardware
A computer in a data center — always on, public IP, high capacity. Just a regular computer with a job description.
Server as software
A program that listens on a port, receives requests, and sends responses. Can run anywhere — data center, your laptop, a Raspberry Pi.
The mom explanation: Think of a restaurant. The kitchen is the computer. The waiter is the server software. Your browser is the customer. The same waiter works in a tiny pop-up (your laptop) or a huge chain (Twitter's data center). Same concept, wildly different scale.
Try it — start your own server

Pick your tool and run this in your terminal, from any folder you want to serve.

terminal
# Navigate to the folder you want to serve
cd ~/my-project

# Start a server on port 8080
python3 -m http.server 8080

# Open your browser to:
http://localhost:8080
What's localhost? A hardcoded alias for 127.0.0.1 — a reserved IP that means "this machine talking to itself." Never leaves your computer.
Chapter 02

The HTTP request lifecycle

Every time your browser loads something, it sends a structured text message to a server and gets a structured text message back. HTTP is just a protocol — an agreed format for those messages.

Request simulator — watch what happens step by step
Browser
you
Browser cache
local disk
Server
localhost:8080
Disk
your files
// Hit "Send request" to simulate the lifecycle
raw HTTP — what the browser actually sends
GET /index.html HTTP/1.1
Host: localhost:8080
Accept: text/html
Connection: keep-alive
                          ← blank line separates headers from body

--- server responds ---

HTTP/1.1 200 OK
Content-Type: text/html
Cache-Control: max-age=3600
                          ← blank line separates headers from body
<html>...</html>        ← the actual file
Chapter 03

HTTP headers

Headers are metadata that travel alongside a request or response — separate from the content itself. Think of them as the label on the outside of a shipping package.

📤

Request headers

Browser → Server. Who's asking, what they accept, cookies they carry, and how they want the response.

📥

Response headers

Server → Browser. What type of content it is, how to cache it, what cookies to set, security rules to apply.

🔑

Format

Always plain text key-value pairs. Key: Value. A blank line separates headers from the body.

🐍

Setting them in Python

Subclass SimpleHTTPRequestHandler and override end_headers() to inject your own.

Cache-Control explorer — click to see what each directive does

max-age=3600

Cache this file. Treat it as fresh for this many seconds before re-requesting.

no-cache

Store it, but always check the server before using the cached copy.

no-store

Never store this anywhere. Request fresh from server every single time.

public

CDNs and browsers are both allowed to cache this file.

private

Browser only. CDN must not cache this — it's user-specific.

stale-while-revalidate

Serve the stale copy instantly, fetch a fresh one in the background.

// Select a directive above to see the HTTP header and what it means
python — custom headers server
from http.server import SimpleHTTPRequestHandler, HTTPServer

class CachedHandler(SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header("Cache-Control", "max-age=3600")
        self.send_header("X-Custom-Header", "hello")
        super().end_headers()

HTTPServer(("", 8080), CachedHandler).serve_forever()
Chapter 04

Origins and the Same-Origin Policy

An origin is three things: protocol + domain + port. Change any one of them and you have a different origin. The browser uses this to enforce security boundaries between sites.

Origin builder — click pieces to toggle and see what makes origins match

URL A (reference origin)

https:// twitter.com :443 /home

URL B — click to change each piece

https:// twitter.com :443 /messages
same origin All three pieces match — browser allows cross-communication

The path (/home, /messages) is always ignored when comparing origins.

Why file:// breaks everything: When you open an HTML file directly, each file is its own origin. Scripts can't talk to other files because they're all "different senders." A local HTTP server gives everything one shared origin — http://localhost:8080 — so fetch(), ES modules, and cookies all work.
Chapter 05

Ports

Every machine has 65,535 ports. Think of them as parking spots — not permanently owned, just grabbed on demand. One process per spot at a time.

Port zones — drag to explore
010234915165535
■ 0–1023: protected (need sudo) ■ 1024–49151: registered / free-for-all ■ 49152–65535: ephemeral
80 HTTP default — browsers assume this for http:// protected
443 HTTPS default — browsers assume this for https:// protected
3000 Node / React dev servers free
5173 Vite default free
8080 Generic HTTP, Python dev server free
5432 Postgres free
Ports are released instantly. Kill your Python server and port 8080 is immediately free. No cleanup. It's a parking spot — you leave, someone else can pull in.
Chapter 06

Caching layers

A cache is a saved copy of something so you don't have to fetch it again. There are four layers, each positioned closer to the user than the one before it.

Cache layer simulator
Browser cache
CDN cache
Server cache
DB cache
Browser cache on your disk
Checks local cache first. If hit → serve immediately. If miss → next layer.
CDN edge cache nearest city
Checks edge node. If hit → serve from nearby server. If miss → next layer.
Server cache (Redis) data center
Checks in-memory store. Avoids hitting the database for repeated queries.
Database cache built-in
DB caches frequent query results internally. If miss → read from disk. Slowest.
Chapter 07

How a CDN cache works

A CDN puts copies of your files on servers around the world. Users get files from the nearest location instead of your one origin server. First request populates the edge. Every request after that is served locally.

CDN request simulator
🧑‍💻
User
🏙️
Edge node
🖥️
Origin server
// Select a user location and hit "Make request"
Edge cache state: Atlanta: cold London: cold Tokyo: cold
Cache busting with fingerprinting: Vite and webpack rename your files on every build — main.a3f9.jsmain.b81d.js. New filename = new cache entry. No CDN purge needed. Your HTML always points to the new file, and the old one expires naturally.
Chapter 08

DNS — the internet's phone book

You type twitter.com. The internet speaks in IP addresses. DNS translates between the two — every single time, in milliseconds, invisibly.

DNS lookup simulator
Check local cache
OS checks if it already resolved this recently
Ask recursive resolver
Your ISP's DNS server — it knows or goes to find out
Root → TLD → authoritative
Chain of name servers narrows down to the right answer
IP returned
Browser connects to that IP on port 443
What you type
twitter.com — human-readable, easy to remember
What the internet uses
104.244.42.65 — machine-readable IP address
localhost is special
Hardcoded in your OS to always be 127.0.0.1. Skips DNS entirely — never leaves your machine.
Ports are invisible
https:// silently adds :443. You only see ports when they're non-default, like localhost:8080.