Rate limits
Backoff strategy
Exponential backoff with jitter; prefer Retry-After on 429.
Overview
For rate_limit_exceeded and other retryable: true codes, use exponential backoff with jitter. Prefer server-provided Retry-After when it is present.
Recommended algorithm
- If
Retry-Afterexists, wait that many seconds (± small jitter). - Else wait
min(cap, base * 2^attempt) + random(0, base)milliseconds. - Stop after a bounded number of attempts; surface the error to the user or queue.
- Never retry when
retryable === false.
javascript
async function sleep(ms) {
await new Promise((r) => setTimeout(r, ms));
}
async function fetchGray(url, init, { maxAttempts = 6, baseMs = 250, capMs = 8000 } = {}) {
let attempt = 0;
while (true) {
attempt += 1;
const res = await fetch(url, init);
if (res.status !== 429 && res.status < 500) return res;
const json = await res.clone().json().catch(() => null);
if (json?.error?.retryable === false) return res;
if (attempt >= maxAttempts) return res;
const retryAfter = Number(res.headers.get("retry-after"));
if (Number.isFinite(retryAfter) && retryAfter > 0) {
await sleep(retryAfter * 1000 + Math.random() * 200);
continue;
}
const exp = Math.min(capMs, baseMs * 2 ** (attempt - 1));
await sleep(exp + Math.random() * baseMs);
}
}Writes and broadcast
Backoff does not make broadcast idempotent. After a timeout, check GET /v1/transactions/receipt before sending the same signed payload again.
Related: Timeouts and retries, Retryable vs not.