Design a low-latency Rate Limiting System
Quick Overview
Design a low-latency rate limiting system handling millions of requests. Discuss consistency, availability, and performance trade-offs.
Walmart
System Design
Software Engineer
Walmart
Software Engineer
Onsite
System Design
Easy
10
Design a low-latency rate limiting system handling millions of requests. Discuss consistency, availability, and performance trade-offs.
Walmart's APIs for search, checkout, and partner integrations need protection from abusive clients and traffic bursts during sales events. The interviewer wants a rate limiter that adds very little latency, works across many gateway nodes, and fails in a predictable way.
What the Interviewer Expects
- Clarify limit keys (user, IP, API key) and the limit granularity
- Compare token bucket, fixed window, and sliding window algorithms
- Design a shared counter store such as Redis with atomic operations
- Keep added latency low with local caching or batching of counter updates
- Decide on fail-open versus fail-closed behavior when the store is unavailable
- Return clear responses such as HTTP 429 with retry headers
Key Topics to Cover
Token bucket
Sliding window
Distributed counters
Redis
Fail-open versus fail-closed
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How would you enforce limits accurately across multiple data centers?
- What happens if Redis becomes unavailable during a flash sale?
- How would you support different limits for different customer tiers?
- How do you prevent a burst at the boundary of a fixed window?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Functional Requirements
- Rate Limiting: The system must allow for configurable rate limits (e.g., 100 requests per minute) per user or IP address.
- Quota Management: Ability to track a...
Capacity Estimation
Assuming we need to handle 10 million requests per minute:
- Per Second: 10 million requests / 60 seconds = ~166,667 requests per second.
- Per User: If we assume an average of 100,000 active ...
Submit Your Answer
Markdown supported