Back to all posts
How to Test Your Rate Limiter with Rotating Proxies

How to Test Your Rate Limiter with Rotating Proxies

November 26, 2026

Rate limiters fail quietly. You add the middleware, the happy path passes, and nobody learns that the counter is keyed on the wrong field, that the window never resets, or that a client can forge the header that picks the key — until a burst of real traffic hits.

A rotating proxy gives you many source IPs without renting servers, and it lets you verify the behavior that matters most: a new IP gets a fresh bucket. Here is a repeatable way to test your own limiter end to end.

What "working" means

Pin the assertions before writing any code:

  1. Requests from one IP, up to the limit, return 200.
  2. The next request returns 429 with a Retry-After header.
  3. After the IP changes, the counter starts over.
  4. After the window elapses, the counter starts over even with the same IP.

If any of the four fails, the limiter is not doing what you think it does.

Why not test from localhost

From localhost every request looks like 127.0.0.1, so an IP-keyed counter has nothing to count. You also cannot check that your edge really strips client-supplied X-Forwarded-For, because there is no edge in the path. Sending the request through a proxy puts a real peer address in front of your app and forces the same code path production uses.

Configure the proxy

Point the test client at the gateway. With RoProxy, each proxy has its own username and password, and one HTTP port carries both HTTP and HTTPS traffic; Pro and Business plans also expose a SOCKS5 port.

PROXY = "http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT"
PROXIES = {"http": PROXY, "https": PROXY}

# Same gateway, SOCKS5 port, if your plan has one:
# SOCKS = "socks5://USERNAME:PASSWORD@GATEWAY_HOST:SOCKS5_PORT"

The socks5:// scheme needs the PySocks extra: pip install 'requests[socks]'.

Set the proxy to sticky mode before you start. Sticky keeps the same IP until you rotate it or it fails, which is what you want while you fill a bucket. Timed mode changes the IP on its own schedule and makes the test flaky.

Step 1: Confirm the exit IP

import requests

def exit_ip():
    r = requests.get(
        "https://api.ipify.org?format=json",
        proxies=PROXIES,
        timeout=10,
    )
    r.raise_for_status()
    return r.json()["ip"]

print(exit_ip())

Run it twice. The same IP both times means sticky mode holds. If the IP moves, every counter assertion below is meaningless.

Step 2: Fill the bucket

Aim at a test route on your own service so you can read the real response.

LIMIT = 10
URL = "https://your-app.example/limited"

def hit():
    return requests.get(URL, proxies=PROXIES, timeout=10)

codes = [hit().status_code for _ in range(LIMIT + 3)]
print(codes)

You want the first LIMIT entries to be 200 and the rest to be 429. Then check the header:

resp = hit()
assert resp.status_code == 429
assert int(resp.headers["Retry-After"]) > 0

Spoof the header on purpose

r = requests.get(
    URL,
    proxies=PROXIES,
    headers={"X-Forwarded-For": "203.0.113.9"},
    timeout=10,
)
print(r.status_code)

If that request is counted as a brand-new client, your app trusts a header any caller can set. Your edge should overwrite it, and your limiter should key on the peer address the edge passes down.

Step 3: Rotate and confirm a fresh bucket

On the Pro and Business plans you can rotate on demand, and the API enforces a minimum wait between calls, so sleep between attempts or handle the error.

import time

ROTATE = "https://backend-api.ro-proxy.com/api/session/SESSION_ID/rotate"

def rotate():
    r = requests.post(
        ROTATE,
        headers={"Authorization": "Bearer API_KEY"},
        timeout=15,
    )
    r.raise_for_status()

before = exit_ip()
rotate()
time.sleep(2)
after = exit_ip()

assert before != after, "IP did not change"
assert hit().status_code == 200

On the Free plan the IP changes on a fixed schedule and cannot be rotated by hand, so run the same two assertions after the next scheduled change instead.

Step 4: Wait out the window

Use a short window on the test route, then confirm recovery without any rotation.

time.sleep(65)  # the test route uses a 60 second window
assert hit().status_code == 200

False positives that waste your morning

  • Trusted headers. If the app reads X-Forwarded-For from any client, a caller can pick their own counter key. The spoof test above catches this.
  • You measured the edge, not your code. If the 429 comes from a CDN or WAF, your limiter never ran. Compare response headers and body before you celebrate.
  • Shared IP. Other traffic on the same IP can fill the bucket, so a 429 on request two is a signal, not proof. Use a different proxy or a route with its own limit.
  • Client retries. A retry policy in the test client inflates the count. Disable retries while testing.
  • Mode drift. If the proxy is in timed mode, the IP can change mid-loop and your counts come from two buckets.

What this does not prove

  • Behavior under concurrency. One client fills one bucket. For more, list your proxies through the API and run one worker per proxy.
  • That your limit values are tuned correctly. The test proves the mechanism, not the numbers.
  • Anything about other people's services. This is for your own limiter.

Running it as a check, not a one-off

  • Point it at staging, not production, and keep LIMIT small.
  • Fail the build on any 429 before LIMIT, any missing Retry-After, or any 200 right after rotation.
  • Give each job its own proxy so parallel runs do not share a bucket.
  • Keep the request rate low; this is a correctness check, not a load test.

Keep it honest

Run this only against services you own or have permission to test, and delete test routes when the experiment ends.

Wrap-up

Fill, assert 429, rotate, assert 200: four checks that turn rate limiting from a production surprise into a small script you can run before every release. On RoProxy the rotate call is a single POST with a bearer key, so the whole loop fits in one Python file.