From aj-geddes-useful-ai-prompts-4
Implements rate limiting, throttling, API quotas, and backpressure mechanisms using token bucket, sliding window, Redis-based distributed, and adaptive algorithms. Useful for protecting APIs, preventing DOS attacks, and managing system load.
How this skill is triggered — by the user, by Claude, or both
Slash command
/aj-geddes-useful-ai-prompts-4:rate-limiting-implementationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- [Overview](#overview)
Implement rate limiting and throttling mechanisms to protect your services from abuse, ensure fair resource allocation, and maintain system stability under load.
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)
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 |
npx claudepluginhub joshuarweaver/cascade-code-languages-misc-1 --plugin aj-geddes-useful-ai-prompts-4Guides rate limiting implementation using token bucket, sliding window counters, Redis Lua scripts, tiered quotas, middleware, headers, and monitoring to protect APIs from abuse and manage quotas.
Implements API rate limiting strategies (token bucket, sliding window, fixed window) to protect APIs from abuse, manage traffic, and enforce tiered limits.
Controls request throughput with token bucket, sliding window, and fixed window algorithms to protect APIs from abuse, enforce usage quotas, and prevent service overload using Redis.