Bird
Raised Fist0
HLDsystem_design~12 mins

Design a rate limiter in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Design a rate limiter

This system controls how many requests a user can make in a given time. It helps protect services from too many requests at once. The key need is to limit requests fairly and quickly without slowing down the service.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  v
Rate Limiter Service
  |
  +--> Cache (for counters)
  |
  v
Backend Service
  |
  v
Database
Components
User
client
Sends requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Receives requests and forwards them to Rate Limiter Service
Rate Limiter Service
service
Checks if user request count is within allowed limits
Cache
cache
Stores request counts per user for fast access
Backend Service
service
Processes allowed requests
Database
database
Stores user data and long-term logs
Request Flow - 12 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayRate Limiter Service
Rate Limiter ServiceCache
CacheRate Limiter Service
Rate Limiter ServiceCache
Rate Limiter ServiceAPI Gateway
API GatewayBackend Service
Backend ServiceDatabase
Backend ServiceAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Cache
Impact:Rate Limiter cannot quickly check or update request counts, causing possible incorrect rate limiting or slower responses
Mitigation:Fallback to database for counts with slower response; add cache replication and monitoring to reduce downtime
Architecture Quiz - 3 Questions
Test your understanding
Which component first checks if a user’s request count is within limits?
AAPI Gateway
BRate Limiter Service
CLoad Balancer
DCache
Design Principle
This design uses a fast cache to track request counts for quick decisions, preventing overload. The Load Balancer and API Gateway separate concerns for scalability and security. Fallbacks ensure reliability even if cache fails.