Most outages I've read about weren't caused by too little hardware. They were caused by a default setting nobody questioned, which worked fine until the traffic changed shape.
I build Bugpit, a browser game where your system design runs against simulated traffic and breaks. This week I added three levels where you can't buy your way out: a bigger machine is over budget, so the fix has to be a setting. Each one comes from something real systems actually do.
1. Your cache evicts the wrong things
The default: LRU, least recently used. When the cache is full, throw out whatever nobody asked for in the longest time.
When it breaks: a news site gets 24,000 requests a second, and the cache answers 85% of them. Then a search engine crawler reads every old article once.
To LRU, every one of those crawled articles is the most recently used thing in the cache. So it keeps articles nobody will read again, and throws out the front page to make room.
In the sim:
- the hit rate falls from 85% to 47%
- the database gets about twice the reads it was sized for
- 12.9% of requests fail, and retries make it worse
The fix: LFU, least frequently used. It counts how often each key is read, so one read from a crawler can't outrank a page read thousands of times a minute.
In Redis, that's one line:
maxmemory-policy allkeys-lfu
Where you've seen this: MySQL's InnoDB buffer pool doesn't put newly read pages at the front of its LRU list. It inserts them in the middle, so a full table scan can't flush out the hot pages. Caffeine, the Java cache library, uses W-TinyLFU partly because it holds up under scans.
The catch: LFU trusts history. When something new gets popular, old favourites with huge counts hang around, and the new page keeps getting evicted. There's no best policy, only one that fits your traffic.
2. Your load balancer takes turns
The default: round robin. Server 1, 2, 3, 4, then 1 again. It never looks at how busy anyone is.
When it breaks: a team dashboard gets 7,000 requests a second on 4 servers that can handle 8,000 together. On paper there's room. But 1 request in 10 is a CSV export that takes 10 times as long as the rest.
A server that picks up a few exports in a row gets stuck on them, and round robin keeps handing it new requests anyway. They pile up behind the exports while another server sits idle. Round robin spreads requests evenly, not work. On average the servers are fine, but the busiest one overloads.
The fix: least connections. Send each request to the server with the fewest requests in flight. A server stuck on exports has many open, so new requests go elsewhere until it catches up.
In NGINX:
upstream app {
least_conn;
server app1:8080;
server app2:8080;
server app3:8080;
server app4:8080;
}
Where you've seen this: HAProxy has balance leastconn and recommends it for long sessions. AWS Application Load Balancer offers "least outstanding requests" as an alternative to round robin.
When round robin is fine: when every request takes about the same time. Then taking turns spreads the work evenly too, and it costs nothing to track.
3. Your rate limiter counts per clock minute
The default: a fixed window. Count requests per minute, and reset to zero on the minute. It's the easiest thing to build:
// Fixed window: easy to write, easy to game.
const key = `${userId}:${Math.floor(Date.now() / 60_000)}`;
const count = await redis.incr(key);
await redis.expire(key, 60);
if (count > LIMIT) return reject(429);
When it breaks, part 1: scrapers learn the reset. They send a full minute's worth at 0:59, the counter resets, and they send another full minute's worth at 1:00. For a moment your servers get twice the limit.
In the sim, a limit of 7,000 that 4 servers can carry lets 14,000 through around each reset, and the servers fall over right on the minute. Halving the limit stops the crash, but then you turn away half the people you could serve all day long.
The fix: a sliding window. Count the last 60 seconds, whenever now is. There's no reset to aim for. Cloudflare has written about using a sliding window approximation for their rate limiting for this reason.
When it breaks, part 2: real users aren't smooth either. Say each user gets 10 requests a second and averages 2. Then they open a dashboard that fires 30 calls at once. Any window, fixed or sliding, counts 30 in one second and refuses 20 of them. Half the widgets show "Too many requests".
The fix: a token bucket. Each user gets a bucket that refills at 10 tokens a second and holds up to 30. Each request spends one token. A user who was quiet has a full bucket, so the burst goes through, and the average still can't go over 10.
// Token bucket: bursts spend saved tokens, the average stays capped.
function allow(bucket, now, rate = 10, capacity = 30) {
const elapsed = (now - bucket.updatedAt) / 1000;
bucket.tokens = Math.min(capacity, bucket.tokens + elapsed * rate);
bucket.updatedAt = now;
if (bucket.tokens < 1) return false;
bucket.tokens -= 1;
return true;
}
Where you've seen this: AWS API Gateway throttling is set as a rate plus a burst, which is a token bucket. Stripe's engineering post on rate limiters describes token buckets in Redis.
The pattern
All three defaults have something in common:
| Default | Breaks when | Fix |
|---|---|---|
| LRU eviction | something reads everything once | LFU |
| Round robin | some requests are much slower | Least connections |
| Fixed window | clients time the reset, or users burst | Sliding window, token bucket |
None of them are wrong. Each one assumes your traffic is smooth and even, and real traffic usually isn't. A bigger machine hides the problem for a while. Knowing what your traffic looks like fixes it.
Try breaking them yourself
All three are free levels in the Core concepts section of Bugpit. Each starts already broken. Press Run, watch what fails, and change one setting. The numbers in this post come straight from those levels.
If you've been bitten by one of these defaults in production, I'd love to hear the story in the comments.
Top comments (1)
The fixed window reset timing is the quiet bug. Scrapers just time the reset and double the limit.