interviewmind

Design a rate limiter

“Design a rate limiter” is a system design interview question. Design a rate limiter for a public REST API. Each API key may make 1,000 requests per minute. A request over the limit gets 429 Too Many Requests with a Retry-After header. The API runs on many stateless servers behind a load balancer and peaks at about 50,000 requests a second. Below is what to cover and 3 hints; press Practice and Dana, the interviewer, asks it out loud while you sketch the design.

Updated · By InterviewMind

Practice this question

Free in your browser, no account.

The problem

System design

Design a rate limiter for a public REST API. Each API key may make 1,000 requests per minute. A request over the limit gets 429 Too Many Requests with a Retry-After header.

The API runs on many stateless servers behind a load balancer and peaks at about 50,000 requests a second.

Things to cover

  • The algorithm: fixed window, sliding window or token bucket
  • Where the limiter runs, and where the counts live
  • Keeping counts consistent across servers
  • What happens when the counter store is slow or down

Hints

Open one at a time, and try the question again after each.

Hint 1

Start with the load: 50,000 requests a second means 50,000 counter checks and increments a second. That’s too many for a relational database, and easy for an in-memory store like Redis.

Hint 2

The core is a counter or a token bucket per API key, kept in a store every API server shares. Do the check and the increment in one atomic step, so two servers can’t both let the last request through.

Hint 3

The hard part is the store being slow or down. Decide whether to fail open and let requests through, or fail closed, and consider a rough local limit on each server as a fallback.

Practice it out loud

In the practice room Dana reads the question aloud in your browser’s own voice, with captions, and you answer in the editor beside it, in a design doc with the requirements filled in and a section for each part. It’s free and needs no account. Run the InterviewMind desktop app beside it and it hears the question the way it hears a real call, so you can see what it would show you in the live round.

Practice this question

More system design questions

interviewmind

Clarity under pressure.

Download for macOSWindows

On an Intel Mac? Download for Intel