Skip to content
On this page

Request retries are the practice of automatically re-sending an HTTP request that failed, instead of giving up on the first error. Networks drop packets, servers return temporary 503s, and rate limiters fire 429s - many failures are transient and succeed on a second or third attempt. Retry logic detects which failures are worth retrying, waits a sensible interval (ideally growing each time), and re-sends the request, turning a flaky connection into a reliable one without manual intervention.

Quick facts

Retry onTimeouts, connection resets, 429, 500, 502, 503, 504
Do not retry onMost 4xx (400, 401, 403, 404) - retrying will not help
BackoffExponential (1s, 2s, 4s...) plus random jitter
SafetySafe for idempotent requests (GET); care needed for POST
CapA max-attempts limit prevents infinite loops

How retry logic works

A retry wrapper sits around your HTTP call. When a request fails, it inspects the failure to decide whether retrying could help. Transient errors - a network timeout, a connection reset, or a 5xx server error - are worth retrying because the cause is temporary. A 429 rate-limit is retriable too, after waiting for the limit to reset. Most 4xx client errors are not: a 404 means the page is not there, and a 401 means you are not authenticated, so re-sending the identical request just wastes attempts. When a retry is warranted, the wrapper waits, then re-sends, up to a maximum number of attempts before it gives up and raises the error.

Exponential backoff and jitter

Retrying instantly is the wrong move - if a server is overloaded, an immediate retry adds to the load that caused the failure. The standard pattern is exponential backoff: wait 1 second, then 2, then 4, then 8, doubling the delay each attempt so a struggling server gets room to recover. On top of that, add jitter - a small random offset to each wait - so that many clients retrying at once do not all fire again at the exact same instant (the "thundering herd" problem). When the server sends a Retry-After header, honor it: it tells you exactly how long to wait, which beats any guess. This same backoff logic underpins polite rate-limit handling.

Why retries matter for web scraping

At scale, transient failures are not the exception - they are constant. A job fetching a million pages will hit thousands of timeouts and temporary blocks purely by volume, and a scraper without retries simply loses that data. Good retry logic recovers it automatically. The one thing to watch is idempotency: a GET is safe to retry because re-fetching a page has no side effect, but retrying a POST that places an order could place it twice, so non-idempotent requests need care (an idempotency key, or no retry). A managed scraping API builds retries in - it detects soft failures like a block page returned with a 200 status, rotates to a fresh IP, and retries transparently, so you get the data instead of an error. See also self-healing scrapers.

Code example

python
import time, random, requests

RETRIABLE = {429, 500, 502, 503, 504}

def fetch(url, max_tries=4):
    for attempt in range(max_tries):
        try:
            r = requests.get(url, timeout=10)
            if r.status_code not in RETRIABLE:
                return r            # success or a non-retriable error
        except requests.RequestException:
            pass                    # timeout / connection reset - retry
        sleep = (2 ** attempt) + random.uniform(0, 0.5)  # backoff + jitter
        time.sleep(sleep)
    raise RuntimeError(f'failed after {max_tries} attempts')

Next in When requests get blocked · 5 of 6

A vendor-specific code worth recognising on sight.

What Is Cloudflare Error 1015?

Related terms

Concept map

Concept map

How What Are Request Retries connects

The terms most directly tied to this one. Hover a node to see its neighbours, click to preview, drag to rearrange.

0 terms · 0 connections
You are here · Web Scraping APIs
Building map…

Frequently asked questions

Which HTTP errors should I retry?

Retry transient failures: network timeouts, connection resets, and 5xx server errors (500, 502, 503, 504), plus 429 rate limits after a wait. Do not retry most 4xx client errors (400, 401, 403, 404) - they signal a problem with the request itself that re-sending will not fix.

What is exponential backoff?

Exponential backoff is a retry strategy where the wait between attempts doubles each time - 1s, 2s, 4s, 8s - instead of staying constant. It gives an overloaded server progressively more time to recover and prevents a tight retry loop from making the problem worse.

Why add jitter to retries?

Jitter is a small random delay added to each backoff interval. Without it, many clients that failed at the same moment would all retry at the same moment, hammering the server in synchronized waves (the 'thundering herd'). Jitter spreads those retries out over time.

Is it safe to retry any request?

Idempotent requests like GET are safe to retry because repeating them has no side effect. Non-idempotent requests like a POST that creates a record need care - a blind retry could duplicate the action. Use an idempotency key, or avoid retrying writes, to stay safe.

Last updated: 2026-06-08