Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aj-geddes avatar

Rate Limiting Implementation

  • 456 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

rate-limiting-implementation is a Claude Code skill that designs and codes API rate limits with token buckets, sliding windows, Redis counters, and middleware for developers protecting services from abuse and cost spikes

About

rate-limiting-implementation is a backend skill from aj-geddes/useful-ai-prompts that walks developers through concrete rate-limit designs instead of vague throttling advice. The skill covers token bucket and sliding window algorithms, Redis-backed counters, HTTP middleware hooks, and per-tenant quota policies so public and multi-tenant APIs survive abuse without runaway infra bills. Developers reach for rate-limiting-implementation when adding first-class limits to REST or GraphQL gateways, internal microservices, or AI proxy endpoints where burst traffic and shared keys need enforced ceilings. Expect implementation-ready patterns for middleware placement, header semantics, and storage choices rather than high-level security checklists alone.

  • Token bucket and sliding window
  • Redis-backed counters
  • Per-user and per-IP quotas
  • Middleware enforcement
  • Graceful 429 responses

Rate Limiting Implementation by the numbers

  • 456 all-time installs (skills.sh)
  • Ranked #948 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill rate-limiting-implementation

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs456
repo stars305
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you implement API rate limiting with Redis?

Design and code API rate limits using token buckets, sliding windows, Redis counters, middleware, and per-tenant quotas to protect services from abuse and cost spikes.

Who is it for?

Backend developers adding production-grade throttling to public or multi-tenant APIs who want algorithm-specific implementation steps.

Skip if: Teams that only need CDN edge caching or WAF rules without application-layer quota logic in their own services.

When should I use this skill?

The user asks to add rate limits, token buckets, sliding windows, Redis throttling, or per-tenant API quotas.

What you get

Rate-limit middleware code, Redis counter schemas, per-tenant quota rules, and HTTP 429 response handling.

  • rate-limit middleware code
  • redis counter configuration

Files

SKILL.mdMarkdownGitHub ↗

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:

GuideContents
Token Bucket Algorithm (TypeScript)Token Bucket Algorithm (TypeScript)
Redis-Based Distributed Rate LimiterRedis-Based Distributed Rate Limiter
Express MiddlewareExpress Middleware
Sliding Window Algorithm (Python)Sliding Window Algorithm (Python)
Tiered Rate LimitingTiered Rate Limiting
Adaptive Rate LimitingAdaptive 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

Related skills

How it compares

Choose rate-limiting-implementation for app-layer quota code; use edge WAF or CDN rules when limits should terminate before traffic hits your origin.

FAQ

Which rate-limit algorithms does rate-limiting-implementation cover?

rate-limiting-implementation covers token bucket and sliding window algorithms, plus Redis-backed counters, HTTP middleware integration, and per-tenant quotas. The skill targets APIs that must block abuse while allowing controlled bursts.

Does rate-limiting-implementation include middleware examples?

rate-limiting-implementation includes middleware placement and enforcement patterns so limits run before route handlers. Developers get guidance on counters, tenant scoping, and returning HTTP 429 when quotas are exceeded.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.