Designs rate limiting and throttling systems for APIs — algorithms, distributed storage, standard headers, and copyable snippets for ASP.NET Core, Node, and Redis.
Ships in claude-skills-collection. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Identifier chaque endpoint par profil de risque :
| Profil | Exemples | Limite indicative |
|---|---|---|
| Authentification | /login, /token, /forgot-password | 5 req/min/IP |
| Mutation sensible | /pay, /transfer, /sms-otp | 10 req/min/user |
| Lecture lourde | /search, /export, /report | 20 req/min/user |
| Read standard | /products, /users/me | 300 req/min/user |
| Webhook entrant | /webhook/* | 500 req/min/source IP |
Distinguer les identités : IP (anonyme), API key (machine-to-machine), user ID (session).
| Algorithme | Avantage | Inconvénient | Quand l'utiliser |
|---|---|---|---|
| Fixed window | Très simple | Burst doublé à la frontière de fenêtre | Prototypage, admin interne |
| Sliding window log | Précision parfaite | RAM O(n) par client | Haute précision, faible trafic |
| Sliding window counter | Bon compromis | Légère approximation (≤ fenêtre) | API publique standard |
| Token bucket | Burst contrôlé, filling régulier | Implémentation plus complexe | APIs REST, cas général |
| Leaky bucket | Débit constant, protection aval | Latence artificielle | Files d'attente, systèmes fragiles en aval |
Règle de décision rapide : si le client légitime a besoin de pics courts → token bucket ; si le système aval ne tolère pas les pics → leaky bucket ; si la simplicité prime → sliding window counter.
# config/rate-limits.yaml
tiers:
anonymous: { rpm: 10, burst: 15 }
free: { rpm: 100, burst: 150 }
pro: { rpm: 1000, burst: 1500 }
enterprise: { rpm: 10000, burst: 15000 }
endpoints:
/auth/login: { rpm: 5, scope: ip }
/auth/forgot: { rpm: 3, scope: ip }
/api/pay: { rpm: 10, scope: user }
/api/export: { rpm: 5, scope: user, cost: 10 } # coût variable
RateLimiter)// Program.cs
builder.Services.AddRateLimiter(opt =>
{
opt.GlobalLimiter = PartitionedRateLimiter.Create<HttpContext, string>(ctx =>
{
var key = ctx.User.Identity?.Name ?? ctx.Connection.RemoteIpAddress?.ToString() ?? "anon";
return RateLimitPartition.GetSlidingWindowLimiter(key, _ => new SlidingWindowRateLimiterOptions
{
PermitLimit = 100,
Window = TimeSpan.FromMinutes(1),
SegmentsPerWindow = 6,
QueueProcessingOrder = QueueProcessingOrder.OldestFirst,
QueueLimit = 0
});
});
opt.OnRejected = async (ctx, ct) =>
{
ctx.HttpContext.Response.StatusCode = 429;
ctx.HttpContext.Response.Headers.RetryAfter = "60";
await ctx.HttpContext.Response.WriteAsJsonAsync(new
{
error = "rate_limit_exceeded",
retry_after = 60
}, ct);
};
});
// Appliquer : app.UseRateLimiter();
express-rate-limit + Redis)import rateLimit from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import { createClient } from 'redis';
const redis = createClient({ url: process.env.REDIS_URL });
await redis.connect();
export const apiLimiter = rateLimit({
windowMs: 60_000,
max: 100,
standardHeaders: 'draft-7', // RateLimit-* headers RFC 6585
legacyHeaders: false,
store: new RedisStore({ sendCommand: (...args) => redis.sendCommand(args) }),
keyGenerator: (req) => req.user?.id ?? req.ip,
handler: (req, res) => res.status(429).json({
error: 'rate_limit_exceeded',
retry_after: Math.ceil(res.getHeader('RateLimit-Reset') as number - Date.now() / 1000)
})
});
-- token_bucket.lua (KEYS[1]=bucket_key ARGV[1]=capacity ARGV[2]=refill_rate ARGV[3]=now_ms)
local key = KEYS[1]
local capacity = tonumber(ARGV[1])
local rate = tonumber(ARGV[2]) -- tokens/seconde
local now = tonumber(ARGV[3])
local bucket = redis.call('HMGET', key, 'tokens', 'last_refill')
local tokens = tonumber(bucket[1]) or capacity
local last = tonumber(bucket[2]) or now
local elapsed = (now - last) / 1000
tokens = math.min(capacity, tokens + elapsed * rate)
if tokens >= 1 then
tokens = tokens - 1
redis.call('HMSET', key, 'tokens', tokens, 'last_refill', now)
redis.call('EXPIRE', key, math.ceil(capacity / rate) + 10)
return 1 -- OK
else
return 0 -- rejeté
end
Appel Go/Node/C# : EVALSHA <sha> 1 user:42 100 1.67 <epoch_ms>.
HTTP/1.1 200 OK
RateLimit-Limit: 100
RateLimit-Remaining: 43
RateLimit-Reset: 1719230460
RateLimit-Policy: 100;w=60
# Sur 429 :
HTTP/1.1 429 Too Many Requests
Retry-After: 17
Content-Type: application/json
Utiliser RFC 9110 Retry-After (secondes) sur tous les 429. Éviter d'exposer les compteurs précis sur les endpoints d'auth (aide les attaquants à calibrer leurs bots).
// Upstash Redis (Edge / Vercel / CF Workers)
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
const ratelimit = new Ratelimit({
redis: Redis.fromEnv(),
limiter: Ratelimit.slidingWindow(100, "1 m"),
analytics: true,
});
const { success, remaining, reset } = await ratelimit.limit(userId);
if (!success) return new Response("Too Many Requests", { status: 429 });
rate_limit.rejected_total{endpoint, tier, reason} sur chaque 429.{user_id, ip, endpoint, limit, window, timestamp} dans un index dédié pour post-mortem.| Piège | Conséquence | Correction |
|---|---|---|
Compter par IP derrière un load balancer sans X-Forwarded-For | Tous les clients partagent la même IP (celle du LB) | Lire X-Forwarded-For ou CF-Connecting-IP ; configurer trust proxy |
| Fixed window sans décalage aléatoire | Thundering herd à chaque reset | Sliding window ou jitter sur le reset |
Pas de Retry-After sur 429 | Les clients retentent immédiatement, amplifiant la charge | Toujours retourner Retry-After |
| Même limite pour toutes les routes | Endpoint léger et endpoint coûteux identiques | Coût variable (cost-per-request) ou limites par endpoint |
| In-memory sur instances multiples | Chaque instance a son propre compteur → 10× la limite réelle | Redis partagé obligatoire dès la deuxième instance |
| Rate limiting sans auth | L'attaquant tourne les IPs librement | Coupler auth + rate limiting ; CAPTCHA sur les endpoints publics sensibles |
| Limites trop strictes sans whitelist | Blocage des crawlers légitimes, monitoring, CI/CD | API keys internes exemptées, whitelist CIDR |
/ping = 0).x-rate-limit) et dans les headers dès la première requête (pas seulement sur 429).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/claude-skills-collection:dev-rate-limiter-designerfrom claude-skills-collection
npx claudepluginhub vantaflow/claude-skills-collection --plugin claude-skills-collection348 skills in this plugin
/agent-a2a-protocol-guideGuide du protocole Agent-to-Agent (A2A) de Google pour l'interopérabilité entre agents IA — découverte, communication et collaboration inter-agents, avec exemples de code, critères de décision et pièges à éviter. Se déclenche avec "A2A", "agent-to-agent", "protocole A2A", "Google A2A", "interopérabilité agents". Also triggers on "agent-to-agent protocol", "agent interoperability", "connect two agents"./agent-agent-observabilityInstrumentation technique d'un agent IA — tracing distribué des appels LLM et outils, spans, métriques custom, corrélation de logs et dashboards de supervision. Pour les alertes et garde-fous de production, voir agent-monitoring-setup. Se déclenche avec "observabilité agent", "tracing agent", "LangSmith", "Langfuse", "OpenTelemetry agent", "spans LLM", "corréler les logs agent". Also triggers on "trace my agent", "LLM tracing", "agent spans"./agent-api-caller-subagentSous-agent spécialisé dans les appels API REST/GraphQL avec retry, auth et transformation de données. Se déclenche avec "sous-agent API", "API caller agent", "agent qui appelle une API", "REST agent", "HTTP agent", "API integration subagent", "external API agent". Also triggers on "subagent that calls an API", "API calling agent", "agent HTTP requests".Other plugins' skills for the same job