aj-geddes avatar

Rate Limiting Implementation

This walks you through implementing rate limiting from token buckets to sliding windows, with examples in TypeScript and Python. You get Redis-based distributed rate limiting for multi-server setups, Express middleware you can drop in, and patterns for tiered limits and adaptive throttling. The best practices section is solid on the operational details: returning 429s with Retry-After headers, handling burst traffic, and not storing state in memory when you're running multiple instances. If you're building a public API or need to prevent abuse without breaking legitimate users during traffic spikes, the reference implementations cover the algorithms that actually matter in production.

skills.sh installs
507
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill rate-limiting-implementation --agent claude-code

Installs into .claude/skills of the current project.

Files

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;

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Backend & APIs, AI & Agent Building
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1rshankras avatargeneratorsrshankras/claude-code-apple-skillsCode generator skills that produce production-ready Swift code for common app components. Use when user wants to add logging, analytics, onboarding, review prom505skills.sh installs
2glitternetwork avatarpinme-emailglitternetwork/pinmeUse this skill when a PinMe project (Worker TypeScript) needs to integrate email sending (send_email). Guides AI to generate correct Worker TS code.504skills.sh installs
3openclaudia avatartelegram-botopenclaudia/openclaudia-skillsSend messages, images, and marketing content to Telegram channels and groups via Bot API. Create formatted posts, polls, and media content for Telegram communit504skills.sh installs
4glitternetwork avatarpinme-llmglitternetwork/pinmeUse this skill when a PinMe project (Worker TypeScript) needs to call OpenRouter-backed LLM APIs, including models, chat/completions, streaming, or OpenRouter w503skills.sh installs
5hkuds avatarcli-anything-wiremockhkuds/cli-anythingPython CLI harness for WireMock HTTP mock server administration503skills.sh installs
62ykwang avatarhtml-visual2ykwang/agent-skillsGenerate an interactive single-file HTML visualization — mockup, wireframe, ERD, flowchart, chart, slides, architecture diagram, dashboard, timeline, mindmap, k500skills.sh installs