← all chapters
CHAPTER 01
3 DIAGRAMS · ~9 MIN

Scalability Fundamentals

Vertical scaling has a ceiling. Horizontal scaling has a coordination problem. Caching has an invalidation problem. Pick your problems deliberately.

01.1 · CONCEPT

Load Balancing

A single endpoint hides a pool of workers. The load balancer decides which one gets the next request — and notices when one stops answering.

ALGORITHMS
Round-robin is fair but blind. Least-connections beats it under uneven request weights. Consistent hashing wins when cache locality matters.
L4 vs L7
L4 (TCP) is faster and protocol-agnostic. L7 (HTTP) can route by path, header, or cookie — the price is parsing every request.
HEALTH CHECKS
Active probes catch dead servers fast but cost requests. Passive checks are free but slow to react. Most prod setups run both.
FIG · 01.1
ROUND ROBIN · L7C1C2C3C4LBHAProxyServer 1healthyServer 2healthyServer 3healthyweights · health checks · sticky sessions
01.2 · CONCEPT

Caching Layers

Every layer between user and database is an opportunity to skip work. The closer to the user, the cheaper the hit — and the harder the invalidation.

LATENCY BUDGET
Disk: ~10ms. Network round-trip same-AZ: ~0.5ms. Redis hit: ~1ms. CPU cache: ~ns. Move hot data up the stack relentlessly.
WRITE STRATEGIES
Write-through is safe but slow. Write-back is fast but loses data on crash. Write-around skips the cache on writes — good for write-heavy, read-rare data.
INVALIDATION
TTL is the lazy default. Explicit purge on write is correct but couples writers to the cache. Versioned keys (key:v17) sidestep both.
FIG · 01.2
READ PATH · CACHE HIERARCHYBrowser0 mshit rate 95%CDN Edge20 mshit rate 80%App Cache1 mshit rate 65%Redis2 mshit rate 50%Database20 mshit rate 35%each layer absorbs load · misses cascade down
01.3 · CONCEPT

CDN & Edge

Distance is latency you can't optimise away — unless you move the bytes closer. CDNs put cached responses (and increasingly compute) in hundreds of POPs around the world.

ANYCAST ROUTING
Every POP advertises the same IP. BGP routes the user to the topologically closest one. No DNS tricks required.
ORIGIN SHIELD
A single mid-tier cache in front of origin collapses thundering-herd misses from hundreds of edge POPs into one request.
EDGE COMPUTE
Workers/Lambda@Edge run logic at the POP — A/B tests, auth, request rewriting — without a round-trip to your region.
FIG · 01.3
EDGE POPS · ANYCAST ROUTINGOriginus-east-1POPEUPOPAPACPOPAMERPOPSAcache static · TLS termination · DDoS shield
NEXT · 02
Databases at Scale