"Design a rate limiter" is one of the most common system design questions. The usual answer is a counter in Redis: read the count, compare it with the limit, write the count plus one. It passes every test that sends one request at a time.
I spent a week building the version that holds up, as a runnable system in the interview-traps repo : one design lesson, five traps and a rollup. Each trap has the naive code, the fix and a proof test. This post is the short version: one rule that covers most of the bugs, the example that shows it best, and how the other bugs fit around it.
One caveat up front, from the repo itself: Redis in this week is an in-process stand-in ( shared/kv.ts ) with Redis semantics, so everything runs with nothing but Node. The clock is pinned and crashes are injected on purpose, so each run is repeatable.…