rate-limiting-design
Skill0 starsChanged 5 months agoMITView on GitHub
Designs rate limiting, throttling, and load shedding to protect systems while staying fair across clients. Use when protecting an API or dependency from overload, designing quotas, preventing abuse, or when a service falls over under traffic spikes or noisy-neighbor load.
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 32
Limiter as SPOF: if the rate-limit store is down, do you fail open (lose protection) or closed (lose availability)?
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rate Limiting Design
A rate limiter is an admission-control system that trades rejected requests for system survival. Its job is to fail a few requests cheaply so it doesn't fail all requests expensively.
Decide what you are actually protecting
- The protected resource: CPU, a downstream dependency, a database connection pool, money. The limit must map to the resource's true capacity, not a round number.
- The unit of fairness: per-user, per-IP, per-API-key, per-tenant, global. The wrong unit lets one tenant starve the rest (noisy neighbor) or punishes shared NATs.
- The dimension: requests/sec, concurrent requests, bytes, or cost-weighted (a search query ≠ a health check).
Algorithm choice and its behavior
- Token bucket: allows bursts up to bucket size, smooths to refill rate. Best general default.
- Leaky bucket: constant output rate, no bursts. Good for protecting a fixed-throughput downstream.
- Fixed window: simple but has a 2x burst at window boundaries — a real exploit.
- Sliding window log/counter: accurate, more memory. Use when boundary bursts matter.
- Concurrency limit (semaphore): often better than rate for protecting against slow requests — caps in-flight work, which is what actually exhausts resources.
Distributed enforcement
- Per-node limits don't sum to a global limit; N nodes each allowing R gives N×R. Use a shared store (Redis) with atomic ops, or allocate quota slices per node with periodic rebalancing.
- The limiter store itself must not become the bottleneck or SPOF — local fallback (fail-open vs fail-closed) is a deliberate choice with opposite risks.
Adversarial validation
- Thundering retry: rejected clients retry immediately and in sync, turning a limit into a self-amplifying storm. Return
Retry-Afterand require backoff + jitter; without it the limiter increases load. - Limiter as SPOF: if the rate-limit store is down, do you fail open (lose protection) or closed (lose availability)? Decide explicitly per endpoint.
- Cost asymmetry: an attacker sends the most expensive requests under the limit. Cost-weight the limit, don't count requests.
- Boundary burst: fixed window lets 2x through at the edge — can that 2x kill the downstream?
Non-obvious risks
- Rate limiting upstream of a queue just moves the overload into the queue (bufferbloat) — limit at admission, shed early.
- Returning 429 still costs work (auth, parsing); for true overload you need load shedding that drops cheaply before expensive work.
- Graceful degradation (serve stale/partial) often beats hard rejection for user experience under load.
Output structure
Deliver: the protected resource and its real capacity, the fairness unit and cost dimension, the algorithm with burst behavior, the distributed-enforcement mechanism with fail-open/closed decision, the client-backoff contract (Retry-After), and the load-shedding path for true overload.
In this repository29 other files it gives its agents.
- adversarial-code-reviewSkill
- api-contract-designSkill
- attack-surface-mappingSkill
- authn-authz-design-reviewSkill
- benchmark-designSkill
- capacity-scalability-planningSkill
- concurrency-race-analysisSkill
- data-consistency-modelingSkill
- data-exfiltration-analysisSkill
- distributed-consensus-designSkill
- error-handling-architectureSkill
- event-driven-architectureSkill
- experiment-designSkill
- hypothesis-falsificationSkill
- incident-rca-postmortemSkill
- legacy-refactoring-strategySkill
- literature-synthesisSkill
- metrics-designSkill
- multi-layer-caching-strategySkill
- mvp-scope-cuttingSkill
- performance-profilingSkill
- requirements-disambiguationSkill
- secrets-management-auditSkill
- statistical-validity-analysisSkill
- supply-chain-risk-analysisSkill
- system-decomposition-synthesisSkill
- threat-modelingSkill
- tradeoff-decision-frameworkSkill
- user-failure-mode-mappingSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

