Load Balancing & Autoscaling
Spread traffic, route around failures, add capacity before it is too late.
Load balancers spread requests across instances and, with health checks, stop sending traffic to dead ones. Autoscaling adds instances when CPU stays high — but new instances need time to boot.
Concepts
- Health checks
- Without them a load balancer keeps sending requests to a crashed instance.
- Autoscaling lag
- CPU must stay high for a while, then instances boot: plan headroom for the gap.
- Rate limiting
- Rejecting excess traffic fast at the edge protects everything behind it.
- Zone failures
- Losing an availability zone removes half the instances at once.
Lab
Problems
- YouTube: Viral Video — Medium — A video goes viral: 4× traffic and an exploding transcoding backlog.
- Uber: Rush Hour — Hard — A poison message stalls ride matching, then rush hour doubles traffic.
- E-commerce Flash Sale — Hard — Black Friday: 5× traffic, and every order hits a single MySQL primary.
- Live Leaderboard: The World Final — Hard — The world final starts: four times the spectators on live connections, twice the score updates, and the final’s leaderboard becomes the hottest partition in DynamoDB.
- Stock Exchange: The Opening Bell — Hard — At the opening bell order flow doubles for a minute and four times the retail users stream quotes. Orders must be acknowledged within 45 ms at p99, and nothing can boot in time.
- Booking.com: Holiday Search Surge — Hard — Holiday deals go live: searches ×5. The search index, the search tier’s threads and the availability database’s connections all run out — each for a different reason.
- Slack: The All-Hands Announcement — Hard — The CEO posts in #general: everyone comes online at once, #general becomes the hottest partition in Cassandra, and then a zone of the gateway fleet disappears.
- E-commerce Checkout: The Gray Zone — Hard — Zone B’s network starts dropping packets — health checks still pass — and the inventory service slows down behind three layers of retries.
- LeetCode: Weekly Contest Start — Hard — The contest starts: eight times the coders for two minutes, every one opening the same four problems and submitting — and each submission holds a serverless execution for its whole judge run.
- Multi-Region: Losing us-east-1 — Hard — The primary region goes dark. The standby region has the data — but half the capacity, and its API still calls the identity service in the region that just died.
- Stripe: The Noisy Tenant — Hard — One integration starts a runaway backfill at 15× its normal rate, and then the identity provider that validates every API key goes down for fifteen minutes.
- Gray Failure — Easy — The network to pool B drops 85% of packets. Every instance there is healthy, so the health checks keep sending it half of all traffic.
- Skip the Hop — Easy — A webhook burst triples traffic for a minute. The ingest service in front of SQS cannot boot new instances in time — and partners retry every failure twice.
- The Canary Is Coughing — Easy — Half of traffic runs the new release, and its new dependency just slowed down. v2 fails about a third of requests — not enough to trip a breaker, plenty to break the SLO.
- The Load Balancer Is the SPOF — Easy — GameDay at peak: the chaos team kills one zone while a launch adds 50% traffic. Your single HAProxy lives in that zone.
- One Partner, Everyone’s Outage — Easy — A partner’s batch job hits the API at 15× its usual rate. The shared backend saturates and the premium partners fail with it.
- Connections, Not Requests — Easy — A live final brings 3× the viewers online — and 15 seconds in, a zone drops half of the gateway fleet. CPU stays low the whole time.
- Idle CPU, Full Threads — Easy — The payment vendor gets 10× slower. checkout’s CPU drops, the autoscaler scales nothing — and a quarter of the requests are rejected.
- Cold-Start Cliff — Easy — A push notification sends 8× traffic in one second. Lambda scales — but every new execution spends seconds in a cold start.
- Fastly: When the CDN Disappeared — Hard — Your only active CDN returns errors worldwide. A second CDN is under contract but cold, the origin can serve a fifth of the traffic, and every second counts.
- Slack: Return-to-Work Monday — Hard — The first Monday after the holidays: logins ramp from 8:50, everyone is back at 9:00, instances take three minutes to provision and the transit network starts dropping packets.
- Netflix: Christmas Eve — Hard — On Christmas Eve the primary region’s load balancers lose their state. The other region has half the instances, a cold cache, a small recommendations fleet — and two seconds to take everyone.
- AWS us-east-1: The Endpoint That Vanished — Hard — The regional database endpoint stops resolving. Two services depend on it, the replica is 75 ms away, and nothing new can launch until the database is back.
- Pokémon GO: Fifty Times the Plan — Hard — Launch day brings eight times the worst case you planned for. Clients retry three times, one park has every spawn, the world database is write-bound and map tiles melt their API.
- Fortnite: 3.4 Million Concurrent — Hard — A new season launches: three times the players at once. The profile database runs out of write capacity, the presence service out of connections, and every login hammers the token service.
- Hotstar: Twenty-Five Million for the Final Over — Hard — A cricket final: traffic doubles at the toss and jumps fivefold when the star walks in. Autoscaling is minutes too slow, ranking cannot scale at all, and everyone reads the same live score.
- Shopify: The Celebrity Flash Sale — Hard — A celebrity’s product drop brings eighty times their usual traffic onto the shared platform. No other merchant may notice, no fan’s order may be lost — and the drop starts in one minute.
- Black Friday: The Whole Day — Hard — Doors open at T+150s — and then the payment provider browns out, the catalog cache crashes and a zone disappears, one after another. Instances take two minutes to boot. One plan has to survive all of it.
- Cutover Night: Migrating the Core — Hard — Move all traffic from the legacy core to the new stack tonight. The new stack is cold, its first real traffic exposes a latent bug, the morning starts at T+240s, and the legacy hardware is switched off at T+300s.
- Betting Exchange: The Last-Minute Goal — Hard — A goal in the last minute: six times the punters for forty seconds, all on one market, with a 120 ms latency budget. Nothing boots in time, the ledger cannot grow, and a lost bet is a regulatory incident.
- Active-Active, Half-Broken — Hard — Two regions share the traffic. East starts dropping packets to its database — health checks stay green — the evening peak arrives, and then West’s cache restarts. Moving everyone to West is the trap.
- Inference Platform: The GPU Shortage — Hard — A viral demo quintuples the free tier, a customer starts a batch backfill, and then half the GPUs disappear for ninety seconds. There are no more GPUs anywhere — and the paid customers have an SLA.
- SaaS: The Enterprise Onboarding — Hard — Your biggest customer ever starts importing ten years of data on a Tuesday afternoon — on the shared stack — while half your customers’ webhook endpoints slow down. Existing tenants must not notice.
Codelays runs in your browser: turn on JavaScript to use it.