Module 2: Networking & Web
Life of a Request
Trace a web request from URL entry to HTML rendering — DNS, TCP/TLS, CDN, load balancer, app, DB, and browser critical rendering path.
If you can narrate the path of one HTTP request, you can place every system design box in the right layer. This walkthrough is your canvas for adding CDN, LB, cache, and DB later.
What you will learn
- Walk DNS → TCP/TLS → CDN/LB → app → data stores → response
- Know where TLS termination, cookies, and caching sit
- Separate document, API, and static-asset paths
- Spot major latency contributors along the path
- Explain what the browser does after bytes arrive
Why this walkthrough matters
- Interviewers listen for whether you know which hop owns which job. Naming boxes in order beats jumping straight to microservices.
- Gives a shared diagram for the rest of the design
- Shows where latency and failure can appear
- Clarifies edge (CDN/WAF) vs origin (app/DB) responsibilities
- Prevents putting caches or DBs in the wrong layer
1. URL & DNS resolution
- The browser starts with a URL. Before any TCP connect, it needs an IP for the hostname.
- Check browser / OS DNS cache, then resolver (ISP or public DNS)
- Resolver may follow NS records / CNAME chains to an A/AAAA answer
- TTL controls how long that answer can be reused
- CDN setups often return an edge IP close to the user, not the origin IP
2. TCP connect & TLS
- With an IP in hand, the client opens a transport connection and usually encrypts it.
- TCP three-way handshake adds at least one round trip
- TLS handshake negotiates keys and certificates (extra RTTs unless session is resumed)
- HTTP/2 and HTTP/3 multiplex many requests on fewer connections
- Connection reuse (keep-alive) avoids repeating this cost on every asset
3. Edge: CDN, WAF, reverse proxy
- Public traffic rarely hits app servers first. An edge layer terminates TLS and applies policy.
- CDN edge may serve cached static or even cached HTML/API responses
- WAF inspects HTTP for common attacks before origin
- Reverse proxy / LB chooses a healthy backend and can compress or rate-limit
- TLS often terminates here; backends may use plain HTTP on a private network
4. Load balancer → application
- The LB spreads requests across identical app instances. Health checks remove bad nodes.
- L4 balances TCP connections; L7 can route by host/path/header
- Algorithms: round-robin, least connections, latency-aware variants
- Sticky sessions are optional — prefer shared session store when scaling out
- App server authenticates, authorizes, and starts the business workflow
5. App → caches, DB, dependencies
- Most user latency after the edge is waiting on data and other services.
- Read path often checks Redis/Memcached before the primary DB
- Writes go to the primary (or a queue) depending on the design
- Sync calls to payment/search/recommendation services stack on the critical path
- Timeouts, retries, and bulkheads protect the request from a slow dependency
6. Response path back to the browser
- The app builds a response; proxies may add headers, compress, or cache along the way back.
- Status code + headers (cache-control, set-cookie, content-type) travel with the body
- Edge may store cacheable responses for the next user
- Cookies / tokens establish session for later requests
- Errors should be intentional (4xx/5xx) with enough signal for clients to retry safely
7. Browser parse & critical rendering path
- For document navigations, work continues after the first HTML bytes arrive.
- Parse HTML → build DOM; CSS → CSSOM; combine into a render tree → layout → paint
- HTML discovers CSS, JS, images, fonts — each can trigger more network requests
- Blocking scripts/styles delay first paint; async/defer and critical CSS help
- Static assets should hit CDN with long cache TTLs and fingerprinted filenames
Three paths to keep distinct
- One product usually has more than one request shape. Do not force them through the same boxes.
- Document path — HTML shell, SEO, first paint
- API path — JSON/gRPC for app data, auth-heavy, often uncacheable at CDN
- Static path — JS/CSS/images/videos from CDN/object storage
- Uploads / streaming — may bypass normal page caching and use different timeouts
Latency checklist along the path
- When p99 is bad, walk the chain and name the saturated hop.
- DNS / cold connect / TLS — connection setup cost
- Edge miss → origin — cache effectiveness
- LB queue / unhealthy targets — capacity and health
- App CPU or lock time — compute contention
- DB / cache / dependency RTT — data-plane wait
- Large payloads / uncompressed responses — transfer time
Interview framing
- Use this order at the start of almost any web system design.
- Sketch client → DNS → edge/CDN → LB → app → cache/DB → response → browser
- Mark TLS termination and where cookies/tokens are set
- Split static vs API traffic on the diagram
- Add the first optimization at the slowest labeled hop — not everywhere
- Reuse this canvas when you later add queues, shards, or multi-region
Quick revision checklist
- Draw the full path before diving into services.
- Separate static asset path from API path.
- Mention TLS termination at LB/CDN.
- Label sync vs async dependency calls.
- Talk TTFB and rendering separately for page loads.
- Use the path as a latency debugging checklist.
FAQs
Where does a WAF sit?
Usually at the edge or reverse-proxy layer, inspecting HTTP before traffic reaches app servers.
Does every request hit the database?
No. CDN and application caches can answer many reads. Writes and cache misses are what typically reach the primary store.
Where should TLS terminate?
Commonly at the CDN or load balancer so certificates are managed at the edge. Backends often speak HTTP on a private network; some designs re-encrypt to the app (TLS everywhere).
Why do pages make so many requests?
HTML references CSS, JS, images, and fonts. Each is its own fetch — ideally from a CDN. HTTP/2 multiplexing reduces connection overhead but not the work itself.
What is the difference between CDN and load balancer?
A CDN caches and serves from many edge locations close to users. A load balancer distributes traffic across origin/app instances. Many architectures use both.
How do cookies fit into the path?
The server (or edge) sets cookies on the response. The browser stores them and sends matching cookies on later requests to that site — often used for session identifiers.
Learner’s Task
- Practice out loud for 8–10 minutes. Narrate one page load end-to-end without skipping hops.
- Pick a site action (open home page or submit login) and list every hop from DNS to browser paint.
- Mark where TLS terminates, where a CDN can cache, and where the DB is touched.
- Split the diagram into document vs API vs static asset paths.
- Circle the two hops most likely to dominate p99 for your action and say why.
- Write a 4-sentence closing: path summary, TLS/edge note, data hop, and one optimization at the bottleneck.