Designs client-side rate-limit discipline for APIs: self-throttling token buckets, exponential backoff with jitter, 429 handling, per-key quotas, and load-testing retry logic before a provider throttles you mid-run. Use when writing an API client, SDK, or worker that must survive strict provider rate limits.
./install.sh api-rate-limit-designname: api_rate_limit_design description: Designs client-side rate-limit discipline for APIs: self-throttling token buckets, exponential backoff with jitter, 429 handling, per-key quotas, and load-testing retry logic before a provider throttles you mid-run. Use when writing an API client, SDK, or worker that must survive strict provider rate limits.
Make API clients behave well under rate limits: never fire a request you expect to be rejected, and when rejection happens, back off in a way that does not make the problem worse. This skill covers the client side only (self-throttle, backoff, retry policy), not server-side enforcement.
X-RateLimit- / RateLimit- headers opportunistically. Do not assume any API emits them.TokenBucket at 80-90% of the provider's stated rate, with capacity sized to the burst you actually need. One bucket per quota key (host, API key, or endpoint) via BucketRegistry. The burst of the first 5 permits at 10 req/s with capacity 5 flows instantly; the 6th waits ~100ms. Pacing below the limit is cheaper than eating 429s.Retry-After, wait that long (parse both forms: delta-seconds and HTTP-date; clamp to >= 0). A server-supplied wait always beats a computed one, and if both RateLimit and Retry-After fields appear, Retry-After takes precedence.sleep = random(0, min(cap, base * 2^attempt)). Exponential backoff alone synchronizes retrying clients into lockstep waves; jitter is what actually spreads the load.Retry-After, then check the request timeline: no synchronized retry waves, no instant retries on an HTTP-date Retry-After, and the budget trips instead of hanging.Any client built with this skill ships:
Retry-After precedence, full-jitter backoff with stated base/cap, max attempts, and a total retry budget.Retry-After parser handling both RFC 9110 forms, clamped >= 0.Retry-After) always wins over computed backoff.bin/rate_limit.py implements the whole pattern dependency-free and self-tests offline:
python3 bin/rate_limit.py --self-test
Import TokenBucket, BucketRegistry, parse_retry_after, full_jitter, and call_with_retry directly when building a client.
references/backoff-formulas.md: the three jitter strategies, Brooker's verdict, parameter guidance.references/retry-after-and-headers.md: 429, Retry-After forms, header families, caching rule.references/testing-retry-logic.md: how to load-test the retry loop against a stub.publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e
No ratings yet — be the first to rate it.