Understand what the rate limit response means

An API works during manual testing but begins returning 429 when a scheduled import starts. Retrying immediately makes the error more frequent. Several workers may each appear to obey their own delay while collectively exceeding the same account-wide allowance. The limit might apply to a token, user, endpoint, or entire organization.

Start with the provider's response headers and quota documentation. Record the endpoint category, status, request identifier, and next eligible retry time. Do not record authorization headers. Check whether all processes share a budget and whether a catch-up job is trying to consume a day's work in a few seconds.

Parse both forms of Retry-After

Retry-After can contain a number of seconds or an HTTP date. Treating every value as a number loses date-based instructions; treating seconds as milliseconds causes an aggressive loop. Use the server's documented value when present, allow for clock differences, and place any longer wait in a durable scheduler instead of keeping a request open.

This helper returns a non-negative delay in milliseconds. It rejects malformed values and falls back to bounded exponential backoff with jitter. The fallback is intentionally small for an interactive example; a production worker should persist its next attempt time and apply an overall attempt budget.

javascript example
function retryDelay(value, attempt, now = Date.now()) {
  if (typeof value === 'string' && value.trim() !== '') {
    const text = value.trim();
    if (/^\d+$/.test(text)) {
      const ms = Number(text) * 1000;
      if (Number.isFinite(ms)) return ms;
    } else {
      const date = Date.parse(text);
      if (Number.isFinite(date)) return Math.max(0, date - now);
    }
  }
  const ceiling = Math.min(30_000, 1000 * 2 ** attempt);
  return Math.floor(ceiling / 2 + Math.random() * ceiling / 2);
}

Retry the correct operation at the correct scope

Automatic retries are simplest for a safe read such as GET. A failed POST may already have created something, even when the client did not receive a response. Use the provider's idempotency support before automatically repeating a state-changing request. A rate-limit handler should not silently repeat an irreversible action.

Coordinate rate limits across workers using one shared scheduler or budget store when the provider's limit is shared. Reduce concurrency and spread routine work over time. After a long outage, process the backlog gradually rather than releasing every overdue job at once. A quota that resets tomorrow is different from a short burst limit.

Verify the retry policy under a controlled limit

Use a mock server or development endpoint that returns a sequence of 429 and successful responses. Test a seconds value, an HTTP date, a past date, a missing header, and malformed text. Ensure a very long server delay is persisted rather than truncated into an early request.

Count total calls, not just eventual successes. The policy should stop after its configured attempt budget and expose the item for later handling. Monitor retry delay and pending age alongside error rate. A successful request after dozens of rapid failures is still an unhealthy integration that can affect other applications using the same account.

  1. Test both Retry-After formats and fallback behavior.
  2. Run concurrent workers against one simulated shared allowance.
  3. Verify writes need an idempotency strategy before retrying.
  4. Check that the retry budget and backlog pacing are enforced.

Sources and further reading