Skip to content
Back to skills

Rate Limiting Implementation

ASecurity

Adds token bucket rate limits per API key or user, with a shared store, correct 429 responses and RateLimit headers, and tests for the edge cases.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 15, 2026
ai-agentsrustapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill rate-limiting-implementation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rate Limiting Implementation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rate Limiting Implementation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-rate-limiting-implementation/badge)](https://www.skillsdirectory.com/skills/workspace-templates-rate-limiting-implementation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rate-limiting-implementation
description: Adds token bucket rate limits per API key or user, with a shared store, correct 429 responses and RateLimit headers, and tests for the edge cases.
---

# Rate limiting implementation

Decide who is limited, by how much, and where the counter lives.

## Steps

1. Choose the key per route: API key or user id for authenticated routes, IP plus account name for login, IP only for anonymous public routes. Check how the real client IP arrives behind your proxy (`X-Forwarded-For` is spoofable unless the proxy overwrites it).
2. Choose budgets from data. Read access logs for the 99th percentile of requests per client per minute and set the limit above it. Give expensive routes (search, export, login) their own lower limits.
3. Implement a token bucket: capacity is the burst, refill rate is the sustained rate. Store tokens and the last refill time under the key in Redis and update them in one Lua script or atomic command; read-then-write races let bursts through.
4. Set a TTL on the keys equal to the time to refill from empty, so memory does not grow.
5. On rejection return 429 with `Retry-After` in seconds and the problem body your API already uses. On success send `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset`.
6. Decide the failure mode when the store is unreachable. Fail open for general API traffic; fail closed for login.
7. Test: burst up to capacity passes, the next request gets 429, waiting one refill interval restores one token, and two keys do not affect each other.

## Rules

- Never trust a client-supplied header as the identity.
- Never use a fixed window counter for strict limits; it allows double the rate at the window boundary.
- Never log full API keys.

## Report

Keys and budgets per route, store and script, failure mode chosen, and tests added.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.