Design Distributed Rate Limiter
Design a distributed rate limiter guarding downstream microservices against 60,000 peak requests/sec. Use fast in-memory token buckets to keep p99 latency under 15ms.
| Category & Difficulty | Distributed Infrastructure · MEDIUM |
|---|---|
| Traffic Profile | 60,000 RPS sustained, 90,000 RPS spike (70% reads / 30% writes) |
| Latency & Availability SLA | p99 < 15 ms · 99.99% availability |
| Monthly Infra Budget | $500/month |
| Commonly Asked At | Stripe, Cloudflare, Twilio |
Scale, traffic & SLA targets
To pass in the DesignTheSystem simulator, your architecture must hold all four targets simultaneously across a 60-second load run (spiking up to 90,000 RPS):
Functional & non-functional requirements
Functional scope
- Limit each user (or API key) to N requests per time window.
- Reject extra requests with 429 and a 'retry after' hint.
Non-functional goals
- p99 latency under 15 ms at the spike.
- At least 99.99% of requests answered.
- Costs no more than $500 a month.
- Checking the limit must add almost no time to a request.
- All servers must agree on a user's count.
- If the limiter itself fails, requests should still go through.
Core challenge: One shared counter per user
Every server must agree on how many requests a user has made in this window. Keep the counters in a shared in-memory store with an atomic increment, not in each server's memory.
What breaks first?
A token bucket: each user has a bucket that refills at a steady rate; each request takes a token. It allows short bursts but caps the average. A sliding window counter is a good alternative when you need smoother limits.
Key architectural trade-offs
- Every request costs a round trip to Redis; local pre-counting can cut that but makes limits less exact.
- Failing open means a burst can get through during a Redis outage.
Starting architecture & how to practise
The simulator starts you with a baseline setup: Traffic Ingress → Core App Tier → Primary Database. Run the baseline under 60,000 RPS to watch exactly which component saturates first, then add caching, queues, replicas, sharding or CDN until latency, availability and cost all turn green.
Common interview questions for Design Distributed Rate Limiter
What are the target SLA and scale numbers for Design Distributed Rate Limiter?
Design for 60,000 RPS sustained (spiking to 90,000 RPS) with a 70% read / 30% write mix, keeping p99 latency under 15 ms, availability at or above 99.99%, and infrastructure spend within $500/month.
What is the main architectural bottleneck in Design Distributed Rate Limiter?
Every server must agree on how many requests a user has made in this window. Keep the counters in a shared in-memory store with an atomic increment, not in each server's memory.
How can I verify my Design Distributed Rate Limiter architecture works under load?
Open the live simulator to wire up load balancers, caches, queues, replicas, or shards and run a 60-second traffic simulation that grades latency, error rate, and monthly cost automatically.
Pair with Low-Level Code Design
Want to design the internal classes and data structures too? Try the matching LLD coding problem: Design Rate Limiter.
Recommended lessons before you build
Shared state every server can see
Keep fast-changing state in one shared place instead of inside each server.
Real-time fan-out with pub/sub
Deliver one message to many connected users within a second.
Queues: accept now, work later
Move slow work off the request and keep a queue from falling behind.
Related Distributed Infrastructure problems
Global Clickstream Analytics
Ingest 150,000 telemetry events/sec (100% writes). Buffer data with partitioned streams and batch-process to persistent storage.
Distributed Web Crawler Sync
Coordinate distributed URL frontier polling and storage for 10,000 pages/sec (60% writes). Use object storage for page bodies and separate fast deduplication filters.
Design Search Autocomplete System
Design Search Autocomplete System: Architect a scalable, highly-available distributed system capable of sustaining 25,000 peak RPS (80% reads). Maintain p99 latency under 80ms with 99.9% availability while optimizing monthly infrastructure cost within $600/mo.
Design Web Crawler
Design Web Crawler: Architect a scalable, highly-available distributed system capable of sustaining 25,000 peak RPS (40% reads). Maintain p99 latency under 80ms with 99.9% availability while optimizing monthly infrastructure cost within $1400/mo.