InfraSim system design guide

Rate limiting: who gets turned away?

Four thousand bot requests a second hit a limited-edition drop. A global rate limit kept the servers calm and refused 59% of the real customers.

Rate limiting means refusing requests above some rate, so that whatever is behind the limit only gets as much work as it can handle. The hard part is not the refusing. It is deciding whose requests to refuse.

A global rate limit counts all traffic together: past 2,000 requests a second, say, the excess is turned away, whoever sent it. A per-client limit counts each caller separately, so one script hammering you hits its own ceiling while everyone else carries on. Bot filtering goes further and drops traffic that looks automated before it reaches anything that costs money.

The experiment

A shop is selling a limited-edition snow globe. About 800 real shoppers' requests a second arrive, served by four medium app servers that can autoscale to twelve, a cache and a database. Thirty seconds in, the drop goes live and scalper scripts arrive: 4,000 requests a second, five bots for every shopper.

We ran it five ways with the same seed. Availability below counts real shoppers only.

Real shoppers' requests served once the bots arrived

  • No limit at all84.4%
  • Global limit, 2,000 rps41.2%
  • Global limit, 1,200 rps24.7%
  • Bot filter at the edge100%
  • Bot filter, turned up to 0.987.4%
From 0:40, after the bots had ramped up. InfraSim, Advent of Outages door 8, seed 261208.
Front doorp95 latencySimulated cost / month
None1,657 ms$1,377
Global limit, 2,000 rps123 ms$2,358
Global limit, 1,200 rps103 ms$1,745
Bot filter90 ms$1,237
Bot filter at 0.975 ms$1,079

The global limit did its job, and that was the problem

With no limit, the bots overloaded the app servers. They autoscaled from four instances to ten and still could not keep up: 15.6% of shoppers' requests failed, the worst second lost 54%, and the p95 hit 1.7 seconds. Adding a 2,000 request-a-second global limit fixed all of that for the servers. The p95 dropped to 123 ms and nothing behind the limit was overloaded.

And 58.8% of real shoppers were turned away.

The limiter saw about 4,900 requests a second and let 2,000 through. It cannot tell a scalper's request from a customer's, so it refused the same share of both. Since five in six requests were bots, most of what got through was bots too. Tightening the limit to 1,200 made the servers even calmer and the shoppers' share worse: 24.7% served. It also cost more than doing nothing: the gateway charges per request, and it was charging for every bot it refused.

A global limit set below your real demand turns a capacity problem into an availability problem. It protects the servers by failing the customers.

Filtering by who is asking

A web application firewall with bot protection on, at its default sensitivity, dropped about three quarters of the bot traffic before it reached anything else. Real shoppers: 100% served, p95 90 ms, and the cheapest bill of the working options, because the cheapest capacity is the capacity you never have to buy.

In real systems the precise tool here is usually a per-client limit: a scalper's script makes dozens of requests a second from one client, and a person makes a few. InfraSim models traffic as aggregate flows rather than individual clients, so its firewall stands in for per-client limits and bot fingerprinting together, and the run shows the outcome rather than the counters: bots filtered, shoppers kept.

Turning the filter up too far

At sensitivity 0.9 the filter was so eager that it blocked 12.6% of real shoppers all the time, including the thirty seconds before any bot arrived. That is the false-positive side of filtering. Measure how many customers you block, not just how many bots.

When a global limit is right

A global limit is still worth having, set near what your system can actually serve. It is the last line that turns overload into a fast, clean rejection instead of slow failure for everyone: compare 1.7 seconds with no limit to 123 ms with one. Just do not let it be the only line, or the one that decides who gets in.

About these numbers

They describe InfraSim's simulation, which models traffic as flows per tick, with a fixed seed so every run repeats exactly. Costs are the game's simulated monthly figures, not any provider's prices.

Break it yourself

This is Advent of Outages door 8, "Limited Edition": the same drop and the same scalpers, free in your browser with no account. The door opens on 8 December and stays open after.

In the InfraSim app, Bot Party (chapter 6, Security & Cost) scores both directions: leave the scrapers in and you pay for them, filter too hard and you block your customers.

New to InfraSim? The first five campaign levels play in your browser right now. No install, no account.

Get InfraSim: System Design Game

InfraSim is a system-design game: drag load balancers, caches, databases and queues onto a canvas, deploy, and watch simulated live traffic flow through what you built. Then survive traffic spikes, zone outages and bot swarms across a guided campaign, endless Survival runs and a Daily Challenge. Tutorial and 15 levels free, with optional InfraSim Pro.

More about InfraSim