KatInterview

Design a Per-User API Rate Limiter Service

System DesignModel answer
MediumModel answerSystem Designsystem designrate limitingdistributed systems

Last updated

Design a distributed rate limiting service that enforces per-user request quotas across a fleet of API gateway nodes at high throughput.

Background

You are a senior engineer at a company that runs a public REST API used by thousands of third-party developers. The API is served by a horizontally-scaled fleet of gateway nodes (stateless, ~50 nodes today, up to 200 nodes in two years). Each developer account gets a plan-based quota, for example:

  • Free tier: 100 requests / minute
  • Pro tier: 5,000 requests / minute
  • Enterprise tier: custom limits, negotiated per account

A request that exceeds the quota must be rejected with HTTP 429 Too Many Requests before it reaches the backend. The decision must be made within the gateway, adding no more than 5 ms p99 latency overhead to any request.

Scale

  • 200 M API requests per day at peak (~2,300 req/s average, 15,000 req/s burst)
  • ~500,000 registered developer accounts; ~20,000 active per minute
  • Multi-region deployment (US-East, EU-West, AP-Southeast)
  • SLA: 99.9% uptime for the rate-limiter decision path

What is expected

  1. Clarify requirements — identify the key axes (accuracy, latency, failure mode).
  2. Choose and justify an algorithm — compare at least two options.
  3. Design the data model and API — what is stored, where, and in what shape.
  4. Sketch the architecture — how gateway nodes interact with the limiter.
  5. Address failure modes — what happens when the rate-limit store is unavailable.
  6. Discuss trade-offs — consistency vs. latency, local vs. global counting.

Hints

Hint 1

Think about what happens when 50 gateway nodes each maintain a local counter — how do they stay consistent, and does exact consistency actually matter?

Hint 2

A pure centralized Redis counter is simple but creates a bottleneck and a single point of failure; how can you reduce the blast radius while keeping latency low?

Hint 3

The sliding-window log is accurate but memory-intensive at scale; the token-bucket and sliding-window counter are cheaper — what is each one bad at?