SystemDesignDraw Logo
SystemDesignDraw

Architecture Whiteboard & Math

Interview FavoriteIntermediate Difficulty7 min read

Design a Distributed Rate Limiter

A rate limiter acts as a digital bouncer at the door of your API, ensuring each client stays within their allowed request limits (e.g. 100 requests per minute) and blocking abusive traffic.

Estimated Traffic50,000 Requests/sec
5-Year Data Footprint50 Gigabytes (Transient)
Target Latency< 15 milliseconds
Availability Target99.99% (4 Nines)
Need custom numbers for your interview?Calculate QPS & capacity in System Design Cheat Sheet →

Live Architecture Studio

Edit components, modify labels, add databases, or redraw connections directly on this canvas:

Browse Component Stencils & Icons →
Blueprint:API Rate Limiter
ZenResetExportFull

Loading API Rate Limiter Blueprint...

Mounting vector diagram elements, nodes, and capacity metrics

Mounting API Rate Limiter...
Loading
Topology Nodes (8) Interactive Canvas
⚡ Interactive Architecture Diagram • Drag & Drop Enabled

1. Problem & Challenge

Malicious bots or buggy third-party scripts can spam your server with 10,000 requests in 1 second. Without a rate limiter, this knocks down databases and crashes service for paying users.

2. Core Building Blocks & Responsibilities

👉 Desliza la tabla para ver roles y responsabilidades
ComponentRolePlain-English Explanation
API Gateway MiddlewareThe BouncerIntercepts incoming HTTP headers (API Key or IP address) before the request ever reaches real backend servers.
Redis In-Memory CounterHigh-Speed LedgerTracks how many tokens or requests each user has made in the last 60 seconds with sub-millisecond lookups.
Token Bucket AlgorithmAlgorithm RuleAdds fresh tokens into a virtual bucket at a steady rate. Each API call consumes 1 token. When the bucket is empty, requests are rejected.
HTTP 429 Error ResponderFeedback MechanismReturns HTTP 429 Too Many Requests along with a Retry-After header telling the client when they can retry.

3. Step-by-Step Request Flow

1

Request Hits API Gateway

Incoming HTTP request is tagged with the user ID or client IP address.

2

Atomic Redis Lookup

A Lua script in Redis checks the remaining tokens and decrements by 1 atomically (preventing race conditions).

3

Decision Point

If tokens >= 0, the request is forwarded to backend microservices. If tokens < 0, it is immediately dropped with HTTP 429.

4. Architectural Trade-offs

Decision:

Client-side vs Server-side Limiting

Chosen: Server-side API Gateway

Rationale: Client-side limits can be easily bypassed by attackers tampering with requests.

Decision:

Centralized Redis vs Local Server Memory

Chosen: Centralized Redis with Local Cache Fallback

Rationale: Centralized Redis handles multi-server clusters accurately so clients cannot bypass limits by round-robining servers.

Interview Tip

Always explain the race condition problem: two simultaneous requests from the same user hitting different servers at the exact same millisecond. Mention Redis Lua scripts as the clean solution.

Distributed Architectures

Explore Related System Blueprints

View All Blueprints (13) →
Beginner Friendly6 min read

TinyURL Shortener

A URL shortener converts a long link (like a 100-character article URL) into a compact 7-character key (like tinyurl.com/xyz123) and redirects visitors in under 15 milliseconds.

Study Architecture →
Streaming & Media9 min read

Video Streaming CDN

Streaming high-definition video to millions of smart TVs and mobile phones requires breaking large 10GB video files into tiny 5-second chunks, encoding each into 20 different resolutions, and caching them right inside local ISP networks.

Study Architecture →
Real-Time & Geo10 min read

Uber Dispatch Engine

A real-time geospatial dispatch system matches riders with the most optimal nearby drivers using 64-bit H3 hexagonal indexing and 2-second batch optimization, minimizing city-wide pickup ETA and driver idle time.

Study Architecture →
Fintech & Ledger11 min read

Stripe Payments Ledger

A resilient financial payments architecture guarantees strict consistency (CP system) using cryptographic idempotency reservation, double-entry balanced postings, and sharded balance locks.

Study Architecture →
Real-Time & Collab9 min read

Figma Multiplayer Engine

A real-time multiplayer document engine uses stateful sticky session routing and server-authoritative operational ordering to sync 2D scene graphs across worldwide collaborators without locking.

Study Architecture →
Feed & Distributed8 min read

Twitter Timeline & Feed

A timeline generation system balances high write amplification against fast sub-50ms reads by pushing tweets to followers of regular accounts, while pulling and merging celebrity tweets on-demand.

Study Architecture →