rate-limiting-implementation▌
aj-geddes/useful-ai-prompts · updated Apr 8, 2026
Implement rate limiting and throttling mechanisms to protect your services from abuse, ensure fair resource allocation, and maintain system stability under load.
Rate Limiting Implementation
Table of Contents
Overview
Implement rate limiting and throttling mechanisms to protect your services from abuse, ensure fair resource allocation, and maintain system stability under load.
When to Use
- Protecting public APIs from abuse
- Preventing DOS/DDOS attacks
- Ensuring fair resource usage across users
- Implementing API quotas and billing tiers
- Managing system load and backpressure
- Enforcing SLA limits
- Controlling third-party API usage
- Database connection management
Quick Start
Minimal working example:
interface TokenBucketConfig {
capacity: number;
refillRate: number; // tokens per second
refillInterval: number; // milliseconds
}
class TokenBucket {
private tokens: number;
private lastRefill: number;
private readonly capacity: number;
private readonly refillRate: number;
private readonly refillInterval: number;
private refillTimer?: NodeJS.Timeout;
constructor(config: TokenBucketConfig) {
this.capacity = config.capacity;
this.tokens = config.capacity;
this.refillRate = config.refillRate;
this.refillInterval = config.refillInterval;
this.lastRefill = Date.now();
this.startRefill();
}
private startRefill(): void {
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Token Bucket Algorithm (TypeScript) | Token Bucket Algorithm (TypeScript) |
| Redis-Based Distributed Rate Limiter | Redis-Based Distributed Rate Limiter |
| Express Middleware | Express Middleware |
| Sliding Window Algorithm (Python) | Sliding Window Algorithm (Python) |
| Tiered Rate Limiting | Tiered Rate Limiting |
| Adaptive Rate Limiting | Adaptive Rate Limiting |
Best Practices
✅ DO
- Use distributed rate limiting for multi-server deployments
- Implement multiple rate limit tiers (per second, minute, hour, day)
- Return proper HTTP status codes (429 Too Many Requests)
- Include Retry-After header in responses
- Log rate limit violations for monitoring
- Implement graceful degradation
- Use Redis or similar for persistence
- Consider cost-based rate limiting (expensive operations cost more)
- Implement burst allowances for legitimate traffic spikes
- Provide clear API documentation about limits
❌ DON'T
- Store rate limit data in application memory for distributed systems
- Use fixed window counters without considering edge cases
- Forget to clean up expired data
- Block all requests from an IP due to one bad actor
- Set limits too restrictive for legitimate use
- Ignore the impact of rate limiting on user experience
- Fail closed (deny all) when rate limiter fails
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.7★★★★★53 reviews- ★★★★★Emma Sethi· Dec 24, 2024
We added rate-limiting-implementation from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Dev Gonzalez· Dec 12, 2024
rate-limiting-implementation reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Soo Mensah· Dec 8, 2024
Useful defaults in rate-limiting-implementation — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Shikha Mishra· Dec 4, 2024
rate-limiting-implementation has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Ishan Patel· Nov 27, 2024
We added rate-limiting-implementation from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Yash Thakker· Nov 23, 2024
Solid pick for teams standardizing on skills: rate-limiting-implementation is focused, and the summary matches what you get after install.
- ★★★★★Aditi Huang· Nov 19, 2024
rate-limiting-implementation fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★James Mensah· Nov 15, 2024
Useful defaults in rate-limiting-implementation — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Henry Mehta· Nov 3, 2024
Registry listing for rate-limiting-implementation matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Kabir Liu· Oct 22, 2024
Keeps context tight: rate-limiting-implementation is the kind of skill you can hand to a new teammate without a long onboarding doc.
showing 1-10 of 53