How the Internet Works: DNS, HTTP, TCP
System Design · Foundations · Basics · 14 min
What actually happens when you type google.com and press Enter.
Before your browser can say 'GET /cart', it asks a chain of directories for the address, shakes hands to open a reliable line, agrees on a secret code, and only then speaks HTTP. The reply comes back stamped with a three-digit code whose first digit tells you who is to blame.
The idea in everyday words
Sending a letter. DNS is the phone book that turns a name (google.com) into a street address (an IP). TCP is registered mail: every page is numbered and re-sent if lost. HTTP is the language written inside the letter: 'GET me the homepage, please'.
The journey of one request
- DNS: browser asks "what's the IP of google.com?" →
142.250.x.x(cached for speed). - TCP handshake (+ TLS for https): open a reliable, encrypted connection.
- HTTP request:
GET / HTTP/1.1, headers (cookies, auth). - Server processes, returns a status code + body (HTML/JSON).
- Browser renders, then fetches CSS/JS/images (often from a CDN).
Status codes you must know
| Code | Means | Example |
|---|---|---|
| 100 / 101 | Informational: Continue / Switching Protocols | 101 upgrades the connection to a WebSocket |
| 200 | OK | page loaded |
| 201 | Created | new user saved |
| 301/302 | Redirect | short link → long link |
| 400 | Bad request | missing field |
| 401 / 403 | Not logged in / not allowed | |
| 404 | Not found | |
| 429 | Too many requests | rate limited |
| 500 / 503 | Server error / unavailable |
The first digit is the family: 1xx informational (not success!), 2xx success, 3xx redirect, 4xx the client's mistake, 5xx the server's problem.
def explain(code):
if code < 200: return "informational"
if code < 300: return "success"
if code < 400: return "redirect"
if code < 500: return "client mistake"
return "server problem"
for c in [101, 200, 302, 404, 429, 503]:
print(c, explain(c))
TCP vs UDP, HTTP versions
- TCP: reliable & ordered (web, APIs, payments). UDP: fast, may drop packets (video calls, games).
- HTTP/2 multiplexes many requests on one connection; HTTP/3 runs on QUIC (UDP) for faster mobile connections.
- WebSockets: keep a two-way connection open, for chat apps and live dashboards. The browser asks to upgrade, and the server replies 101 Switching Protocols.
Step by step
- Type URL:
- DNS:
shop.com → 52.1.2.3 (cached next time)
- TCP + TLS:
3-way handshake, then encryption keys agreed
- HTTP:
GET /cart → 200 OK + HTML
- Assets:
CSS/JS/images from CDN edge near you
Code example
# Rough latency budget for one page load (milliseconds)
steps = {"dns": 20, "tcp+tls": 60, "server": 50, "db": 30, "download": 40}
total = 0
for name, ms in steps.items():
total += ms
print(f"{name:>9}: {ms:3} ms (total {total})")Interview tips
'What happens when you type a URL' is a classic opener: answer in layers.
Know 401 vs 403 and 301 vs 302.
Mention keep-alive and HTTP/2 multiplexing for performance.
Challenge: Classify Status Codes
Return a dict/object counting codes by category: "informational" (100–199), "success" (200–299), "redirect" (300–399), "client" (400–499), "server" (500–599). Only include categories that appear.
Example: classify([200, 404, 201, 503]) → {"success": 2, "client": 1, "server": 1}
Solve it in the browser with tests, hints and an AI coach.
Practice problems
More in Foundations
- What Is System Design?
- 10,000 users at once: what really happens
- How to Approach a System Design Interview
- API Design: REST, GraphQL, gRPC
Previous: How to Approach a System Design Interview · Next: API Design: REST, GraphQL, gRPC