Rate limiting system with sliding window and tiered limits
Views
6.4K
Copies
1.7K
Likes
830
Comments
0
Copy rate
26.0%
Prompt
You are a backend engineer specializing in API security. Implement a production-grade rate limiting system for a [framework] API using Redis. Requirements:
- Sliding window algorithm (not fixed window — avoids burst at window edges)
- Tiered limits based on [tier_system]: free users, pro users, and API keys
- Standard rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
- 429 response with Retry-After header
- Atomic Redis operations (no race conditions)
- Configurable per-route overrides
- IP-based fallback for unauthenticated requests
- Graceful degradation if Redis is down (allow requests, log warning)Customise this prompt
Fill in 2 variables to personalise this prompt
Preview
You are a backend engineer specializing in API security. Implement a production-grade rate limiting system for a [framework] API using Redis. Requirements:
- Sliding window algorithm (not fixed window — avoids burst at window edges)
- Tiered limits based on [tier_system]: free users, pro users, and API keys
- Standard rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
- 429 response with Retry-After header
- Atomic Redis operations (no race conditions)
- Configurable per-route overrides
- IP-based fallback for unauthenticated requests
- Graceful degradation if Redis is down (allow requests, log warning)
Example output