Recipe

Handle rate limits and back off correctly

Do not guess your remaining budget — **read the RateLimit-* headers, slow down before the wall, and on a 429 wait for Reset** with exponential back-off plus jitter.

2 min read

RateLimit-*Read them
JitterAvoid thundering herd
Cap attemptsThen fail

Read the headers

Every response — success or 429 — carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset. When Remaining is low, pace yourself before you hit the wall rather than waiting for the 429. This works on both the public 60/60s ring and the partner token bucket.

Back off with jitter

let delay = base;
for (let attempt = 0; attempt < maxAttempts; attempt++) {
  const res = await call();
  if (res.status !== 429 && res.status < 500) return res;
  const reset = Number(res.headers.get('RateLimit-Reset')) || delay;
  await sleep(reset * 1000 + Math.random() * 250);  // jitter
  delay = Math.min(delay * 2, maxDelay);             // exponential, capped
}

Jitter stops many clients retrying in lockstep; the cap stops the delay growing without bound.

Know when to stop

Cap total attempts and then surface a clear failure — an infinite retry loop is worse than a clean error. Never retry a 4xx that is not 429; those are your bug, not a transient condition. On writes, keep the idempotency key constant across retries.

Frequently asked questions

How long should I wait after a 429?

Read RateLimit-Reset and wait at least that long, adding a little random jitter so you do not retry in lockstep with other clients. Then use exponential back-off if it happens again.

Should I retry 5xx the same way?

Yes — 5xx is transient, so back off exponentially with jitter and a capped number of attempts, exactly as for 429. Keep your idempotency key constant so the retry cannot double-act.

Funding for UK limited companies

Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.