Module 0 — Core Concepts
Request Lifecycle
What happens from the moment you type a URL to seeing the page? Every step explained.
1The Mail Delivery Analogy
Simple Analogy
Sending a web request is like mailing a letter:
✉️
Write Letter
Compose request
📮
Find Address
DNS lookup
🚚
Postal Service
Network routing
📬
Delivery
Response arrives
2Complete Request Flow
When you type https://example.com/api/users and hit Enter:
1
DNS Resolution
Domain → IP Address
1-100ms
Browser needs to convert 'example.com' to an IP address like '93.184.216.34'
What happens:
- 1. Check browser cache (previously resolved)
- 2. Check OS cache (/etc/hosts)
- 3. Query DNS resolver (usually ISP)
- 4. Recursive lookup: Root → TLD (.com) → Authoritative
Visual:
Browser
→Cache?
→Resolver
→93.184.216.34
2
TCP Connection
Establish reliable channel
10-100ms
Three-way handshake to establish a reliable connection
What happens:
- 1. Client sends SYN (synchronize)
- 2. Server responds SYN-ACK (acknowledge)
- 3. Client sends ACK (connection established)
- 4. Now both sides can send data reliably
Visual:
Client
SYN →
Server
← SYN-ACK
ACK →
3
TLS Handshake
Secure the connection (HTTPS)
30-150ms
Establish encrypted channel using certificates
What happens:
- 1. Client Hello: supported cipher suites, random number
- 2. Server Hello: chosen cipher, certificate
- 3. Client verifies certificate against CA
- 4. Key exchange: agree on session keys
- 5. All further communication encrypted
Visual:
Client Hello
↔Server Hello + Cert
→Key Exchange
→🔒 Encrypted
4
HTTP Request
Send the actual request
5-50ms
Browser sends HTTP request with headers and optional body
What happens:
- 1. Method: GET, POST, PUT, DELETE, etc.
- 2. Headers: Host, User-Agent, Accept, Cookies, Auth
- 3. Body: JSON payload for POST/PUT
Visual:
GET /api/users HTTP/1.1 Host: example.com Authorization: Bearer eyJhbGc... Accept: application/json Cookie: session=abc123
5
Server Processing
Handle the request
10-1000ms
This is where your application code runs
What happens:
- 1. Load balancer routes to available server
- 2. Web server (Nginx) receives request
- 3. Application server processes business logic
- 4. Database queries, cache lookups
- 5. Build response
Visual:
Load Balancer
→Web Server
→App Server
→Database
6
HTTP Response
Server sends data back
10-500ms
Response includes status code, headers, and body
What happens:
- 1. Status: 200 OK, 404 Not Found, 500 Error, etc.
- 2. Headers: Content-Type, Cache-Control, Set-Cookie
- 3. Body: HTML, JSON, images, etc.
- 4. May be compressed (gzip)
Visual:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=3600
Content-Encoding: gzip
{"users": [{"id": 1, "name": "Alice"}]}7
Browser Rendering
Display the content
10-1000ms
Browser parses and renders the response
What happens:
- 1. Parse HTML → Build DOM tree
- 2. Parse CSS → Build CSSOM
- 3. Execute JavaScript
- 4. Layout: calculate positions
- 5. Paint: draw pixels on screen
Visual:
HTML → DOM
+CSS → CSSOM
=Render Tree
→🖥️ Page
3Latency at Each Step
Typical Request Timeline (200ms total)
DNS Lookup
20ms
TCP Connect
30ms
TLS Handshake
40ms
Request Send
10ms
Server Processing
80ms
Response Transfer
20ms
Where to Optimize
Server processing (40%) is usually the biggest chunk and what you can control. DNS caching, connection reuse (keep-alive), and CDNs help with the rest.
4Key Optimizations
DNS
- • DNS prefetch (rel="dns-prefetch")
- • Use fewer unique domains
- • Lower TTL for failover
TCP/TLS
- • Keep-alive connections
- • HTTP/2 multiplexing
- • TLS session resumption
Request
- • Reduce payload size
- • Compression (gzip, brotli)
- • CDN for static assets
Server
- • Caching (Redis)
- • Database indexes
- • Async processing
Response
- • Chunked transfer
- • Streaming responses
- • Edge computing
Browser
- • Lazy loading
- • Code splitting
- • Image optimization
5HTTP/1.1 vs HTTP/2 vs HTTP/3
| Feature | HTTP/1.1 | HTTP/2 | HTTP/3 |
|---|---|---|---|
| Connections | Multiple (6 per domain) | Single (multiplexed) | Single (QUIC/UDP) |
| Head-of-line blocking | Yes | Partial (TCP level) | No |
| Header compression | No | HPACK | QPACK |
| Server push | No | Yes | Yes |
| Transport | TCP | TCP | QUIC (UDP) |
6Key Takeaways
17 main steps: DNS → TCP → TLS → Request → Processing → Response → Render
2DNS converts domain to IP. Cache it. Use CDN.
3TCP + TLS adds 50-250ms. Use HTTP/2 multiplexing and keep-alive.
4Server processing is usually the biggest latency. Cache and optimize.
5HTTP/2 multiplexes requests over single connection. HTTP/3 uses QUIC.
6In interviews: trace a request step-by-step, mention optimization at each layer.