Design a rate limiter
The interviewer asks you to build the class that decides, for each request, whether this client has sent too many lately. Picture a school sports day, with one water jug per team under a slow tap. A jug holds so many cups, and a thirsty runner takes one. Nobody stands watching the tap. A tag on each jug says how full it was and when someone last looked, so the helper works out what has run in since, then pours.
It is also asked as "implement a token bucket". The closest other case study is the LRU cache, which also keeps a little state per key under one lock. Interviewers like this question because it is often set as a threading exercise, and the design has two values that must change together. This page is the class-level part. The algorithms are compared on Rate limiting algorithms, and a limit shared by many servers belongs to Rate limiter.
Below is a full 45-minute round on the LLD framework. You are the candidate. At each Guess before you read on, stop and answer first. The full runnable project, with its tests, is a download in Java, JavaScript and Python.
Run the full project
This design as a project you can run, with its tests and a demo. You only need Java 21, Node 24 or Python 3.13. The README says how to run it.
Step 1 · Clarify the requirements and cut the scope
Minutes 0–5 · How this step works
Interviewer: Build a rate limiter.
You: Limited per what, and at what rate?
Interviewer: Per client key. Each may send 10 requests a second, with bursts up to 50.
You: How many clients?
Interviewer: Assume 100,000 active at a time.
You: What does the caller need when a request is refused?
Interviewer: A fast no, and how long to wait, so the gateway can answer 429 with Retry-After.
You: Do many threads call it, and on how many servers?
Interviewer: A gateway's request threads, in one process. Assume one server for now.
You: Is a token bucket the only algorithm you need?
Interviewer: For the API, yes. Someone will ask about logins later.