Skip to content

Rate limiting explained: how it works and how to stay under it

By the ProxyOnly team · 14 Nov 2026 · 5 min read

How rate limiting works, what a 429 and Retry-After mean, and tested Python code that throttles your requests and backs off politely.

Rate limiting is a server restricting how many requests a client can make in a period of time. It protects the service from overload and abuse, keeps usage fair, and controls cost. If you collect data, call APIs or run tests, you will meet it, usually as a 429 Too Many Requests response.

This article explains how limits are enforced, what the response looks like, which limits proxies can and cannot help with, and how to write a client that stays under limits and recovers politely. The Python code in it was tested against a local server that returns 429 and 503 responses.

How rate limits are enforced

A server has to decide which requests belong to the same client, which it does by address, API key, account, session or a combination. Then it applies one of a few common algorithms.

  • Fixed window: allow a number of requests per minute, resetting at the start of each minute. It is simple, but a client can send a full allowance at the end of one window and another at the start of the next, so twice the limit arrives in a short burst.
  • Sliding window: count requests over the last 60 seconds at every moment, which removes that boundary burst.
  • Token bucket: a bucket fills with tokens at a steady rate up to a maximum, and each request takes one. You can burst up to the size of the bucket, then you are held to the refill rate. It is the most common model for APIs.
  • Leaky bucket: requests join a queue that drains at a constant rate, which smooths traffic completely.
  • Concurrency limits: a cap on how many requests may be in flight at once, whatever the rate.

What a limit looks like to a client

The standard response is 429 Too Many Requests, defined in RFC 6585 and described in MDN's page on 429. Some services use 503 Service Unavailable instead. Either may carry a Retry-After header, which tells you how long to wait, as a number of seconds or as an HTTP date.

Many APIs also send informational headers such as X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. These are conventions, not a standard, and their exact meaning varies between services. An IETF working group has a draft for standard RateLimit header fields, which is still a draft and not yet an RFC at the time of writing. Read the documentation of the API you use, and when the headers are there, use them.

For the proxy side of the same response, see 429 Too Many Requests and 403 and 429 errors when scraping.

Per address, per key, per account

Which identity the limit applies to decides whether proxies can help.

  • A limit per IP address is about the address, so spreading requests over several addresses spreads the load. This is the case proxies help with, as covered in proxies for web scraping.
  • A limit per API key or per account follows your credential, so no proxy changes it. Creating extra keys or accounts to get around such a limit usually breaks the service's terms.

Treat a limit as a statement of how much the operator is willing to give you. If you need more than that, the answer is to ask for a higher plan, not to look for a workaround.

How to be a good client

  1. Read the documentation and any rate limit headers before you start.
  2. Cap concurrency, so that you are never hammering the service with many parallel requests.
  3. Add a delay between requests, with a little random jitter so that your requests do not arrive in lockstep.
  4. Honour Retry-After whenever it is present.
  5. When a 429 or 503 has no Retry-After, back off exponentially: wait 1 second, then 2, then 4, and add jitter.
  6. Cache what you have already fetched, and use conditional requests. A request with an If-None-Match header can return 304 Not Modified with no body when the page has not changed, which saves bandwidth, as described in MDN's page on If-None-Match. A 304 still counts as a request on most servers, but it is tiny, which matters when you pay per gigabyte.
  7. Spread work out over time before you spread it over more addresses.

A tested rate limiter and retry helper

This is a token bucket that throttles your own requests, a helper that works out how long to wait from a Retry-After value in either of its formats, and a get function that puts them together:

import random, time, requests
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
class TokenBucket:
    def __init__(self, rate, capacity):
        self.rate, self.capacity = rate, capacity
        self.tokens, self.updated = capacity, time.monotonic()
    def take(self):
        while True:
            now = time.monotonic()
            self.tokens = min(self.capacity, self.tokens + (now - self.updated) * self.rate)
            self.updated = now
            if self.tokens >= 1:
                self.tokens -= 1
                return
            time.sleep((1 - self.tokens) / self.rate)
def retry_delay(value, attempt):
    if value is None:
        return 2 ** attempt
    if value.isdigit():
        return int(value)
    try:
        return max(0, (parsedate_to_datetime(value) - datetime.now(timezone.utc)).total_seconds())
    except (TypeError, ValueError):
        return 2 ** attempt
def get(session, bucket, url, max_tries=5):
    for attempt in range(max_tries):
        bucket.take()
        response = session.get(url, timeout=30)
        if response.status_code not in (429, 503):
            return response
        time.sleep(retry_delay(response.headers.get("Retry-After"), attempt) + random.uniform(0, 1))
    raise RuntimeError(f"gave up on {url}")

Use it like this, with a rate of 2 requests per second and room for a burst of 5:

bucket = TokenBucket(rate=2, capacity=5)
session = requests.Session()
response = get(session, bucket, "https://api.example.org/items")

We tested the code against a local server. With a rate of 4 per second and a bucket of 1, eight requests took 1.79 seconds, close to the expected 1.75. A bucket of 5 let five requests through at once. A Retry-After: 2 response was honoured and the retry succeeded, as was one carrying an HTTP date three seconds ahead, and the function gave up cleanly after the maximum number of tries.

Choosing a rate

Start low and raise it only while the service stays quiet. For a site you do not own, one request per second or slower is a reasonable start. Check whether the site or API documents a limit, and use that. Watch your responses for 429 and for slower answers, which can show that the server is straining before it starts refusing.

Where proxies fit

If a site limits by address and your job needs more requests than one address may make, several addresses spread the load. A rotating gateway does this for you, as described in rotating proxies and backconnect gateways. The aim is to stay within what the site allows for each address, not to push through it. If you are being blocked in other ways, why websites block IPs and proxies covers the other signals, and the guide to avoiding blocks responsibly has a checklist.

Try it yourself

Create an account, add funds from US$1 and order a proxy in the country you need.

Keep reading