What this page is for

Intent: revise all of networking in one go, the night before an interview.
Covers: HTTP messages · what happens when you type a URL · DNS · TCP and UDP · TLS and HTTPS · HTTP caching · origin · CORS.
Time: about 10 minutes. Every topic below links to its quick page and its detailed page.

Words you need first

  • Client / server: the client (your browser or app) asks; the server answers.
  • IP address: a machine’s number on the internet, e.g. 203.0.113.10.
  • Port: a number that picks the program on a machine. HTTPS uses 443, HTTP uses 80.
  • Packet: a small piece of data sent across the network on its own.
  • Round trip (RTT): one message there and the reply back. Most setup steps cost one each.
  • HTTP (HyperText Transfer Protocol): the language of web requests and replies.
  • Header: a name: value line sent with a request or reply.
  • Status code: the 3-digit result of a request, e.g. 200 OK, 404 Not Found.
  • DNS (Domain Name System): the internet’s phone book: turns shop.com into an IP address.
  • Resolver: the DNS server (your ISP’s, or 8.8.8.8) that does the lookup for you.
  • TTL (time to live): how many seconds an answer may be cached.
  • TCP (Transmission Control Protocol): turns lost, out-of-order packets into one reliable, ordered stream.
  • UDP (User Datagram Protocol): sends single messages with no setup and no retries.
  • Handshake: the messages two sides exchange before real data flows.
  • TLS (Transport Layer Security): encrypts the connection and proves the server’s identity. HTTPS is HTTP over TLS.
  • Certificate: a signed file that says “this public key belongs to shop.com”.
  • CA (certificate authority): a company browsers trust to sign certificates.
  • Cache: a stored copy of a reply, reused so you don’t ask again.
  • ETag: a version label for a reply, used to ask “has this changed?”.
  • Origin: scheme + host + port, e.g. https://shop.com:443.
  • Same-origin policy (SOP): the browser rule that a page may read replies only from its own origin.
  • CORS (Cross-Origin Resource Sharing): how a server lets pages from other origins read its replies.
  • Preflight: an automatic OPTIONS request that asks permission before a risky cross-origin request.
  • Cookie: a small value the browser stores for a site and sends back to it, usually your login session.

The big picture

Every topic is one step of loading a page:

The request journey: cache, DNS, TCP, TLS, HTTP request and reply, origin check, page on screen

Topic by topic

1. HTTP message

  • Simply: HTTP is a letter format. The browser sends a request (what it wants, plus labels called headers), and the server sends back a response with a status code saying how it went.
  • A request is a start line (GET /cart HTTP/1.1), headers, a blank line, then an optional body. A response is the same, but its start line has the status (HTTP/1.1 200 OK).
  • Methods: GET reads, POST creates, PUT replaces, PATCH changes part, DELETE removes. Safe = changes nothing (GET, HEAD, OPTIONS; HEAD is GET without the body). Idempotent = repeating it has the same effect as once (GET, HEAD, OPTIONS, PUT, DELETE). POST isn’t idempotent, and PATCH isn’t guaranteed to be.
  • Status families: 2xx worked, 3xx go elsewhere, 4xx your request is wrong, 5xx the server failed. 401 = who are you? 403 = I know you, still no.
  • HTTP is stateless: each request stands alone, and the server remembers nothing between them. Cookies add memory.
  • Trap: POST is not idempotent, so a retried POST can create two orders.
  • Quick · Detailed

2. Request lifecycle

  • Simply: typing a URL kicks off a chain: find the server’s address (DNS), open a connection (TCP), lock it (TLS), then ask for the page (HTTP). Each step must finish before the next.
  • Type URL → cache check → DNS → TCP handshake → TLS handshake → HTTP request → server (load balancer, app, database) → response → browser renders and fetches CSS, JS, images.
  • A first HTTPS visit costs about 4 round trips before the first byte (DNS from the resolver’s cache, TCP, TLS 1.3, HTTP). A full DNS lookup adds several more.
  • A second visit is faster: cached DNS, reused connection, cached files.
  • Trap: the steps can’t overlap; you need the IP before TCP, and TCP before TLS.
  • Quick · Detailed

3. DNS

  • Simply: DNS is the internet’s phone book. A resolver looks up shop.com step by step (root, then .com, then the site’s own server) and hands back its IP address.
  • Browser cache → OS cache → recursive resolver → it asks the root server, then the TLD server (.com), then the authoritative server, which holds the real record.
  • Records: A (IPv4 address), AAAA (IPv6), CNAME (alias to another name), MX (mail server), NS (who’s authoritative), TXT (notes, e.g. verification).
  • Answers are cached for their TTL, which is why DNS changes take time to spread.
  • Mostly UDP port 53 (one small packet each way); TCP when the answer is too big.
  • Trap: the browser doesn’t ask the authoritative server itself; the resolver does the walk.
  • Quick · Detailed

4. TCP and UDP

  • Simply: TCP is a phone call: set up first, nothing lost, everything in order. UDP is a postcard: just sent, faster, but it can get lost.
  • Three-way handshake: SYN → SYN-ACK → ACK, one round trip; both sides exchange random starting sequence numbers.
  • Reliable: every byte is numbered, the receiver ACKs (acknowledges) what arrived, and the sender resends what wasn’t ACKed.
  • Flow control protects the receiver’s buffer; congestion control protects the network.
  • UDP: no handshake, no retries, no ordering. Used for video calls, games, DNS, and QUIC (which HTTP/3 runs on).
  • Trap: TCP doesn’t encrypt anything; TLS does.
  • Quick · Detailed

5. TLS and HTTPS

  • Simply: TLS puts the conversation in a locked box. The server shows a certificate to prove who it is, and both sides agree on a key so nobody in between can read or change the data.
  • TLS gives encryption (nobody can read it), integrity (nobody can change it unnoticed) and identity (the server proves it’s really shop.com).
  • Asymmetric keys (public and private) are used once to agree a secret; fast symmetric encryption protects everything after.
  • TLS 1.3 handshake: 1 round trip (TLS 1.2 needed 2).
  • The server sends a certificate; the browser follows the chain up to a CA it trusts and checks the name and dates. That’s what stops a man-in-the-middle.
  • Trap: HTTPS hides the path and content, but an observer still sees the IP address and the domain name (sent unencrypted in the handshake’s SNI field, Server Name Indication).
  • Quick · Detailed

6. HTTP caching

  • Simply: the browser keeps a copy of a reply. Cache-Control says how long the copy stays fresh, and an ETag lets the browser ask “has this changed?” and get a short 304 if not.
  • Cache-Control: max-age=N = the copy is fresh for N seconds; reuse it with no request.
  • After that it’s stale: the browser revalidates with If-None-Match: <ETag>. Unchanged → 304 Not Modified (no body); changed → 200 with the new copy.
  • no-cache = store it, but check with the server every time. no-store = never store it.
  • Static files get a hash in the name (app.3f9a.js) and cache “forever”; HTML is revalidated.
  • Trap: no-cache doesn’t mean “don’t cache”; that’s no-store.
  • Quick · Detailed

7. Origin and same-origin policy

  • Simply: an origin is one exact address: scheme, host and port. The browser lets a page read replies only from its own origin, so another site can’t read your data.
  • Origin = scheme + host + port. The path doesn’t count. http vs https, api.shop.com vs shop.com, or port 8443 vs 443 each make a different origin.
  • The same-origin policy blocks a page from reading another origin’s replies, iframe content and storage. It still allows loading images, scripts and CSS, submitting forms and following links.
  • Site (scheme + main domain) is looser than origin; cookies’ SameSite uses site.
  • Trap: the policy blocks reading, not sending.
  • Quick · Detailed

8. CORS

  • Simply: CORS is the server’s permission slip. The browser says which origin is asking, and the server’s reply says which origins may read it. If they match, the page can read the reply.
  • The browser adds Origin: https://shop.com; the server replies Access-Control-Allow-Origin: https://shop.com; if they match, the page may read the reply.
  • Preflight: for PUT, PATCH or DELETE, a JSON body or custom headers, the browser first sends OPTIONS to ask.
  • Cookies cross-origin need credentials: "include", Access-Control-Allow-Credentials: true, an exact origin (no *), and a SameSite=None; Secure cookie.
  • Fix CORS on the server (or with a dev proxy), never in the front end.
  • Trap: CORS is not CSRF protection (CSRF, cross-site request forgery: another site makes your browser send a request with your cookies). The request still runs on the server.
  • Quick · Detailed

Top questions

Tap a question to see the answer.

Mental map

Networking mental map: one branch per topic

Watch

ByteByteGo, short video: the whole journey from typing a URL to the page on screen. For the long version, Hussein Nasser’s detailed analysis (about 45 minutes) goes step by step.


← Networking · HTTP message →