Implement Rate Limiting for APIs
Advanced prompt to generate robust rate limiting code for APIs. Includes sliding windows, token buckets, and Redis implementations with error handling.
Prompt Template
Variables to Customize
[PROGRAMMING_LANGUAGE] The programming language for implementation
Example: Python
[FRAMEWORK] The web framework being used
Example: FastAPI
[STORAGE_BACKEND] Storage system for rate limit data
Example: Redis
[RATE_LIMIT_STRATEGY] The rate limiting algorithm to implement
Example: sliding window
[RATE_LIMIT] Number of allowed requests
Example: 100
[TIME_WINDOW] Time period for the rate limit
Example: minute
[API_CONTEXT] Description of the API being protected
Example: REST API for a social media platform with user authentication
Example Output
Pro Tips for Best Results
- Choose sliding window over fixed window to prevent traffic spikes at window boundaries
- Always include rate limit headers in responses to help clients manage their request patterns
- Implement fallback mechanisms when your storage backend (Redis) is unavailable to avoid blocking all traffic
- Consider using different rate limits for different user tiers or API endpoints for better resource allocation
- Add comprehensive logging and monitoring to track rate limiting effectiveness and adjust limits based on usage patterns
Tags
Want 500+ Expert Prompts?
Get the Premium Prompt Pack — organized, tested, and ready to use.
Get it for $29Related Prompts You Might Like
Implement API Pagination System
I need to implement pagination for a REST API endpoint. Please provide a complete implementation with the following requ...
Create Comprehensive Database Backup Strategy
You are a senior database administrator with expertise in enterprise backup strategies and disaster recovery planning. C...
Write Comprehensive Integration Tests
Act as a senior software testing engineer and write comprehensive integration tests for the following system. Your tests...
Generate Professional Deployment Scripts
Act as an experienced DevOps engineer and create a comprehensive deployment script for the following specifications: **...
Handle Concurrent Data Access in Database Systems
You are a senior database engineer specializing in concurrent systems design. I need you to design a comprehensive solut...
Design Database Schema
You are an experienced database architect. I need help designing a comprehensive database schema for [APPLICATION_TYPE]....