Timeouts, Retries & Circuit Breakers
Stop one slow dependency from taking everything down.
A slow dependency holds threads; without a timeout it exhausts the caller. Retries hide blips but multiply load on a struggling service. Circuit breakers fail fast, and fallbacks keep requests succeeding.
Concepts
- Little's law
- Concurrency = throughput × latency: a 10× slower dependency needs 10× the threads.
- Timeouts
- Turn hangs into fast, bounded errors and free the caller’s threads.
- Retry storms
- Each failed call retried 3× quadruples the load on a dependency that is already failing.
- Circuit breakers & fallbacks
- Stop calling a failing dependency for a while; serve a default response or fail over to a secondary.
Lab
Problems
- Payment System — Hard — A third-party fraud API slows down and drags the whole payment flow with it.
- WhatsApp: Message Delivery — Medium — A flaky network link to Kafka, then a Cassandra compaction storm.
- Notification Service: Breaking-News Push — Hard — A breaking story multiplies notifications by eight for the rest of the hour, then the SMS vendor browns out. Alerts must still land within a minute.
- Netflix: Season Premiere at Midnight — Hard — Midnight premiere: five times the viewers, every edge cold for the new episode, an origin that cannot scale — and then recommendations slow to a crawl.
- DoorDash: Friday Dinner Rush — Hard — Dinner rush triples orders for three minutes — more writes than the orders primary can take — and halfway through, the payment provider browns out.
- 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.
- Web Crawler: When the Web Slows Down — Hard — The sites you crawl slow to 1.5 s per page and a transit link starts dropping packets. Your fetchers have idle CPUs and a growing frontier — and you cannot add machines.
- AI Assistant: Launch Day — Hard — The assistant goes viral: five times the questions, a vector database that cannot grow this week, an LLM provider with a hard quota — and then that provider slows down.
- 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.
- Digital Wallet: Payday Friday — Hard — Payday: balance checks and transfers ×2.5 on a distributed SQL ledger with a per-node connection limit — then the bank’s top-up API slows to a crawl behind two retries.
- 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.
- Retries All the Way Down — Easy — The inventory vendor slows down for 30 seconds. The app retries 3×, the Envoy sidecar retries 3× — and the outage outlives the blip.
- The Reindexer Ate the Catalog — Easy — An internal reindex job calls catalog-api 40× harder than usual. Shoppers share the same API and database — and the job’s client retries every 429.
- Vendor Brownout — Easy — The payment processor slows to 1.5 s and loses half its capacity. You cannot fix it, cannot skip it — and every order needs it.
- Auth Is a Total Outage — Easy — Every request validates its token with the auth service. Its database migration will take it down at T+70s — and 12 seconds without auth is 12 seconds without a product.
- Logs in the Hot Path — Easy — Every event the API ingests writes a log line to Elasticsearch synchronously. The log cluster slows to 200 ms — and so does every request.
- Trace Everything — Easy — Every request exports its trace synchronously at 100% sampling. A spike triples traffic and the tracing backend cannot ingest it — so requests fail.
- A Metric per Request — Easy — The API pushes one metric sample per request to Prometheus. A spike quadruples traffic, Prometheus saturates — and the pushes fail the requests.
- Cloudflare: The Regex That Took Down the Edge — Hard — A managed WAF rule with a catastrophic regex pins every edge CPU, and half a minute later a botnet notices. You have seconds — and the WAF cannot simply be switched off for everyone.
- AWS S3: The Day the Object Store Went Dark — Hard — The region’s object store goes down for fifteen minutes. Three different parts of your system depend on it — one of them is your status page — and nothing new can boot.
- 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.
- Roblox: The Service Registry Meltdown — Hard — The service registry every call depends on slows to a crawl, health-check agents keep writing to it, and restarting it does not help. Players must keep playing.
- 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.
- Microservices: The Cascade — Hard — A deploy drops an index: one database gets slow. Three layers of retries, timeouts below the new latency and a non-critical dependency on the critical path turn it into a full outage.
- 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.
- Coinbase: The QR Code Commercial — Hard — A bouncing QR code during the big game: a hundred times the visitors for one minute, sign-ups calling a slow identity vendor, and existing customers checking prices at the same time.
- Healthcare.gov: Launch Day — Hard — Six times the expected visitors on day one: plan browsing that was never cached, a synchronous identity vendor, a data hub that waits on three agencies, and an autoscaling tier with a fixed database.
- 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.
- The Outage Is Over — Now Bring It Back — Hard — The database comes back after ten minutes down — cold, at half capacity. Two million devices flush their offline queues at once, the cache has expired, and the backlog must be gone before the next shift. Recover too fast and you are down again.
- Uber: New Year’s Eve at Midnight — Hard — At midnight, five times the riders open the app in the same few city blocks, drivers double their pings, surge prices update on one hot partition — and the payment provider throttles. You know exactly when it starts.
- 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.
- Social Network: Election Night — Hard — Results night: three times the readers, five times the posts, half of all timeline reads on two candidates, and the push provider slows down. Fan-out, hot keys, search and notifications all at once.
- Payments: The Hot Merchant Account — Hard — A merchant goes viral: payments double and a third of them update one balance row. Then the fraud vendor browns out, and month-end reconciliation starts scanning the ledger. Every payment must be exact.
- 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.