APIs
Rate limiting: multiple-choice review
Six questions that cut across the whole unit. Each mirrors a design call you make under real traffic — not a definition to recite, but a tradeoff to weigh when a customer is hammering your boundary across six nodes at once.
Confirm you can connect algorithm choice, burst behaviour, the distributed-counter trap, atomicity, and the 429 contract — the synthesis the lesson built toward.
The limit is 100/min enforced with a fixed window keyed by {key}:{minute}. What is the worst-case number of requests a client can legitimately land in a ~1-second span, and why?
A public API serves bursty browser clients — a page load fires ~12 requests at once, then idles. You want a fair average rate that tolerates those page-load bursts. Which algorithm fits best?
An in-memory limiter passes every test on a laptop, but in production traffic sails through far above the configured 100/min. Four app nodes sit behind the load balancer. What is the root cause?
You move the counter to Redis and implement it as INCR followed by EXPIRE. Why is a single Lua script the more robust pattern?
An auth service must enforce an exact per-account limit for compliance — no boundary slack, every attempt accounted for. Which algorithm, and what is the cost you accept?
Under a fixed window you reject with 429 and a hard Retry-After of 30 seconds. At the next window edge your error rate spikes again. What happened and what is the fix?
The through-line: how requests fall into windows is where fixed window leaks its 2x boundary burst; sliding window log buys exactness with per-request memory, the sliding counter approximates it for two integers, and token bucket models bursts as a tunable capacity. None of it is real if the counter lives in per-node memory — share it in Redis, make the read-decide-update atomic with Lua, and when you reject, honor the contract with 429 + Retry-After in delta-seconds plus jitter so the reset edge does not become a thundering herd.