/polymath-scalability:rate-limiting-designfrom polymath-scalability
Design rate limits and quotas — token bucket vs window, limit keys, distributed enforcement, 429 headers, fairness, rollout.
Ships in polymath-scalability. 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.
A rate limit protects a resource from a caller. Choose who is limited, by what, at which layer, and what the caller sees — then make the limiter cheaper and more available than the thing it protects.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
Not this when: the goal is shedding load by system health (concurrency/adaptive limits) rather than per-caller quotas — see polymath-architecture:resilience-design; or auth/abuse threat modeling — polymath-security:stride-threat-model.
INCR+EXPIRE or a token-bucket script — one round trip, atomic); local limiters with an even share of the global limit (limit ÷ N instances, fails under uneven routing); local + periodic sync (approximate, cheap); gateway-native. State the accuracy you accept (exact vs ±10–20%) and the added latency (≈ one cache RTT) against the budget. Use key TTLs so state is bounded; watch hot keys for a single abusive caller.429 Too Many Requests with Retry-After (seconds or date) and, if you publish limits, RateLimit-Limit / RateLimit-Remaining / RateLimit-Reset (the IETF RateLimit header fields draft; document your exact semantics). Use a stable error body, a machine-readable code, and a docs link. Don't return 200 with an error, and don't silently drop. 503 is for server overload, 429 for caller quota.Retry-After, back off exponentially with jitter, and cap retries; idempotency keys for retried writes. Publish how to request a higher limit. For outbound calls to a third party, put a token bucket in front of the client sized below their limit and handle their 429s the same way.Retry-After.Rate-limit design: public Orders API
Goal: fairness + protection (capacity 6k req/s sustained on the read path; writes 800/s).
Keys & tiers: API key (primary); per-IP 300/min at the CDN for unauthenticated routes; weights: GET=1, search=10, bulk export=50.
free 60 req/min (1/s) burst 20 · pro 600/min (10/s) burst 100 · enterprise by contract
Oversell check (all keys at sustained limit): free 1/s × 300 + pro 10/s × 400 + enterprise 1,200/s = 5.5k/s < 6k/s capacity [VERIFY: key counts, recompute monthly].
Algorithm: token bucket (rate = sustained, bucket = burst) + concurrency cap 25 in-flight per key.
Enforcement: gateway (edge) for per-key buckets via Redis Lua (atomic, 1 RTT ≈ 1 ms of the 15 ms budget); service-level cost limiter for exports.
Failure: Redis unreachable → fail open on GET with local per-instance cap (limit ÷ instances), fail closed on POST /auth/*.
Contract: 429 + Retry-After + RateLimit-Limit/Remaining/Reset; body {code:"rate_limited", retry_after:…, docs:…}; 503 reserved for load shedding.
Clients: SDK honors Retry-After, jittered backoff, max 3 retries; idempotency keys on POST.
Rollout: observe-only 2 weeks (log would-be 429s) → enforce for free → pro → enterprise; dashboards by key/tier.
Overrides: allow-list with expiry + audit; alert on 429 rate > 1% for a paying key.
Tests: boundary burst, 3-instance accuracy (±10%), Redis down, retry-storm client.
Retry-After, and client retry behavior is defined.GET-then-SET counters in a shared store.200 with an error body, or 429 without Retry-After.What SKILL.md sets; muted values are Claude Code's defaults
6 skills in this plugin
/async-workload-designDesign async and background processing — queue vs stream, worker sizing, idempotency, retries and DLQ, backpressure, priority lanes./capacity-estimationDo back-of-envelope sizing — QPS, bandwidth, storage, cache load, node count — via a script. Not a growth forecast (capacity-plan)./multi-region-designDesign multi-region deployment — active-active vs standby, RPO/RTO, replication and conflicts, routing, failover. Not single-region HA.Other plugins' skills for the same job
npx claudepluginhub mohammadbafkar/polymath --plugin polymath-scalability