Rate Limiting
A mechanism to limit request rates to services and APIs, ensuring stability, fairness and protection against overload and abuse.
Classification
- ComplexityMedium
- Impact areaTechnical
- Decision typeArchitectural
- Organizational maturityIntermediate
Technical context
Principles & goals
Use cases & scenarios
Compromises
- Misconfiguration leads to customer dissatisfaction
- Bypass methods (e.g., IP rotation) reduce effectiveness
- Excessive throttling can impact revenue
- Start with conservative limits and iterate based on metrics
- Differentiate global, customer and endpoint-specific limits
- Provide transparent error and retry signals (Retry-After header)
I/O & resources
- Identifiers (API key, IP, user ID)
- Load and usage patterns
- Service capacity models and SLAs
- Throttle responses (e.g., HTTP 429)
- Metrics and alerts
- Adaptive backoff behavior
Description
Rate limiting is an architectural pattern that restricts the rate of requests to services or APIs to prevent overload and abuse. It specifies allowed request frequencies, throttling behavior, and response signals. Common deployments include API gateways, CDNs, and in-service controls to ensure predictable availability and fair resource sharing.
✔Benefits
- Prevents overload and resulting outages
- Protects against abuse and DoS attempts
- Enables fair resource sharing between customers
✖Limitations
- Incorrect limits can block legitimate users
- Additional infrastructure and latency from central limit services
- Complexity in distributed systems with many identities
Trade-offs
Metrics
- requests per second
Measure of incoming request rate per endpoint or key.
- throttle hits (rejected requests)
Number of requests rejected due to limits.
- latency under throttling
Response time statistics when limiting is active.
Examples & implementations
API gateway with token bucket
An API gateway implements token-bucket algorithms to limit bursts and stabilize endpoints.
CDN-based throttling
A CDN throttles requests to origin servers to smooth spikes and reduce costs.
Service-internal circuit breaker combined with rate limiting
Combining circuit breakers with per-endpoint rate limiting prevents cascading failures.
Implementation steps
Analyze traffic patterns and define SLAs
Choose a limiting strategy (token bucket, leaky bucket, fixed window)
Integrate into gateway/service, set up monitoring and alerting
⚠️ Technical debt & bottlenecks
Technical debt
- Monolithic limiting logic hinders scalable adjustments
- No central metric, cumbersome troubleshooting
- Outdated blacklist mechanisms instead of adaptive rules
Known bottlenecks
Misuse examples
- Setting a too-low default limit for all users
- Ignoring burst behavior during peak times
- Relying solely on client-side rate limiting
Typical traps
- Confusing quotas with real-time rate limiting
- Insufficient testing under realistic load
- Ignoring legal constraints in user segmentation
Required skills
Architectural drivers
Constraints
- • Need for precise identifiers (API key, IP, user)
- • Response time budget must not be exceeded
- • Legal/compliance constraints on user segmentation