The Request Journey — Proxies, Load Balancers & CDNs
What happens when you type a URL, end to end — forward vs reverse proxies, API gateways, L4 vs L7 load balancing, balancing algorithms, health checks, sticky sessions, global load balancing, and how CDNs cache and accelerate content.
What happens when you type a URL
The interview-ready narrative
- URL parsing & HSTS → scheme forced to HTTPS; check the browser cache and service worker.
- DNS → recursive resolution; often lands on an anycast CDN IP.
- Connection → TCP three-way handshake (or QUIC), then TLS 1.3 (SNI, certificate validation, ECDHE key agreement).
- HTTP request → over HTTP/2 or HTTP/3, with cookies, compression preferences.
- Edge → CDN PoP serves cached content or forwards; WAF and DDoS filtering.
- Load balancer → L4 spreads connections; L7 routes
/apivs/static, terminates TLS, retries. - Application → stateless servers; read-through cache; database queries; maybe calls to other services or queues.
- Response → status, headers (
Cache-Control,Set-Cookie, security headers), compressed body. - Rendering → critical rendering path, subresource fetches (multiplexed), JavaScript execution, paint.
Proxies
API gateway
A specialised reverse proxy for APIs: authentication (JWT/API keys/OAuth), rate limiting and quotas, request/response transformation, routing to microservices, aggregation (BFF), observability, API versioning, developer portal. Examples: Kong, Apigee, AWS API Gateway, Envoy-based gateways, Kubernetes Gateway API implementations.
Load balancing
Where load balancers sit
Internet → (DNS / anycast) → L4 LB → L7 LBs / API gateway → service instances
→ internal LBs / service mesh → other services
L4 vs L7
| L4 (transport) | L7 (application) | |
|---|---|---|
| Sees | IPs, ports, TCP/UDP | URLs, headers, cookies, gRPC methods |
| Balances | connections | requests |
| TLS | passthrough possible | terminates |
| Features | raw speed, any protocol | path routing, retries, canaries, auth, caching |
| Examples | AWS NLB, Maglev, LVS, HAProxy TCP | AWS ALB, nginx, Envoy, HAProxy HTTP, Traefik |
Algorithms
| Algorithm | Good for |
|---|---|
| Round robin / weighted round robin | uniform requests |
| Least connections / least outstanding requests | variable request durations |
| Least latency (EWMA) | heterogeneous backends |
| Power of two choices | large fleets, low coordination |
| IP hash / consistent hashing (ring hash, Maglev) | affinity, cache locality |
| Random | simple, surprisingly good at scale |
Health checks and failure handling
- Active checks (
GET /healthzevery few seconds) and passive checks (outlier detection on errors/latency). - Distinguish liveness (restart me) from readiness (don't send me traffic yet).
- Connection draining on deploys and scale-in; slow start for new instances (warm caches/JIT).
- Retries only for idempotent requests, with budgets to avoid retry storms.
- Load balancers themselves are redundant (active-active pairs, managed services, anycast).
Global load balancing
Route users to the best region with GeoDNS/latency-based DNS or anycast global load balancers (Google Cloud LB, Cloudflare, AWS Global Accelerator); fail over between regions on health.
CDNs
| Topic | Notes |
|---|---|
| Routing to PoPs | anycast or GeoDNS |
| Cache key | URL + selected headers/cookies/query params — keep it small for high hit ratios |
| TTLs | from Cache-Control/s-maxage, overridable by CDN rules |
| Invalidation | purge by URL, prefix or surrogate key/tag; prefer versioned URLs (app.3f9a.js) |
| Origin shielding / tiered cache | protects the origin from miss storms |
| Request collapsing | many concurrent misses for one object → one origin fetch |
| Dynamic acceleration | TLS near users, persistent tuned connections to origin, route optimisation |
| Security | DDoS absorption, WAF, bot management, signed URLs/cookies for private content |
| Edge compute | Workers / Lambda@Edge / Fastly Compute for redirects, A/B, auth, personalisation |
| Metrics | cache hit ratio (aim > 90% for static), origin offload, edge latency |
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.