Skip to main content

Sticky vs. Per-Request Rotating Proxies in Python, Node.js, and Playwright: A Practical Field Guide

How session binding works under the hood, plus production snippets for requests, httpx, undici, and Playwright.

Updated 8 min readMarkdown

Most scraper failures blamed on "bad IPs" are actually session-lifecycle bugs: rotating an exit IP mid-checkout, reusing a sticky token past its TTL, or leaking connection pools across workers.

In this guide, we'll break down the practical mechanics of per-request rotating, sticky TTL, and static ISP routing—along with copy-paste code for Python (requests & httpx), Node.js (undici), and Playwright.


1. Choosing the Right Session Mode

Before writing any proxy wrapper, match the session lifetime to the target workflow:

Workload Best Session Mode Why Typical Failure If Misconfigured
Public SERP, product catalog pages, sitemaps Per-request rotation Every HTTP request (or TLS handshake) exits via a fresh IP, distributing rate limits horizontally. Over-using sticky IPs triggers per-IP rate limits (429) quickly.
Pagination with stateful cursors, search filters, CSRF tokens Short sticky session (5–20 min) Preserves IP affinity long enough for multi-step fetches without exhausting a single exit node. Rotating mid-pagination invalidates signed cursor/CSRF tokens (403/419).
Authenticated dashboards, cart flows, browser sessions Long sticky session (15–1440 min) or Static ISP Matches real user session lifetimes; keeps cookie jar + TLS fingerprint + IP aligned. Mid-flow IP flips trigger security re-challenges or instant session logout.
Long-lived headless workers, high-concurrency VM fleets Static ISP (IP Whitelist) Unlimited bandwidth, dedicated IPv4s, zero user:pass header overhead on every CONNECT tunnel. Paying per-GB for heavy media/asset loads in browser farms destroys unit economics.

Rule of thumb: If your target validates session cookies against client IP (X-Forwarded-For / remote peer), never use per-request rotation. Bind one sticky session ID per worker/account and isolate cookies in its own client or BrowserContext.


2. Configuring Proxy Routing Without Proprietary SDKs

Instead of pulling in heavy third-party proxy SDKs, generate standard HTTP or SOCKS5 endpoints in the dashboard Proxy Builder and inject them via environment variables (PV_STICKY_PROXY_URL, PV_ROTATING_PROXY_URL, PV_RESI_PROXY_URL).

On ProxyVerge, there are three gateway layers depending on your workload:

  1. gate.proxyverge.com (Unified Proxy Trio pool — Residential, Mobile, and Datacenter from a single GB balance):
    • Ports: HTTP :10080, SOCKS5 :10800 (with optional UDP over SOCKS5 on Residential and Mobile pools, toggled in the Proxy Builder).
    • Proxy Builder options: Pool type (Residential / Mobile / Datacenter), Country + State or City (mutually exclusive), or ASN (Residential & Mobile only), optional Session ID, and rotation mode: Per-Request, Sticky until exit drops, or 5 / 10 / 15 / 20 / 60 min sticky presets.
    • Output formats: Copy ready-to-use http://..., socks5://..., host:port:user:pass, or cURL strings straight from /account.
  2. resi.proxyverge.com:5555 (Residential Pro — 190+ countries, HTTP & SOCKS5) & mobile.proxyverge.com (Mobile 4G/5G Pro — 155 countries, HTTP & SOCKS5, host/port generated in the Proxy Builder):
    • Both support per-request rotation or configurable sticky sessions with TTL from 1 to 1440 minutes (24 hours).
    • Residential Pro supports country, region/state, city, or ASN targeting (ASN and region/city are mutually exclusive).
    • Mobile 4G/5G Pro supports country + carrier ASN targeting.
    • Exact formatted credentials (host:port:user:pass, user:pass@host:port, http://, socks5://, cURL, and JSON) are exported directly from the dashboard Proxy Builder.

Tip — normalize raw proxy lists locally: Before exporting credentials into env vars or Playwright configs, use our free browser-local ProxyVerge Proxy Format Converter to convert host:port:user:pass, user:pass@host:port, HTTP/SOCKS5 URIs, cURL, Python (requests/httpx), Node.js (undici), and Playwright JSON (runs 100% client-side in your browser—credentials never touch a server).


3. Production Code Examples

A. Python (requests) — Per-Request vs. Sticky Session Isolation

When using requests.Session(), remember that connection pooling (urllib3) reuses open TCP tunnels. For sticky scraping, keep one requests.Session() per worker bound to a sticky Proxy Builder URL; for per-request rotation, export a Per-Request URL from the Proxy Builder and send Connection: close (or avoid pooling) so every call opens a fresh tunnel.

import os
import requests

# Export complete URLs generated by the ProxyVerge Proxy Builder:
# - PV_STICKY_PROXY_URL: e.g. http://USER:PASS@gate.proxyverge.com:10080 (sticky preset + session ID)
# - PV_ROTATING_PROXY_URL: e.g. http://USER:PASS@gate.proxyverge.com:10080 (Per-Request mode)
STICKY_PROXY_URL = os.environ["PV_STICKY_PROXY_URL"]
ROTATING_PROXY_URL = os.environ["PV_ROTATING_PROXY_URL"]

# 1) Sticky session: same exit IP across multi-step login / CSRF requests
with requests.Session() as s:
    s.proxies.update({"http": STICKY_PROXY_URL, "https": STICKY_PROXY_URL})
    r1 = s.get("https://api.ipify.org?format=json", timeout=20)
    r2 = s.get("https://api.ipify.org?format=json", timeout=20)
    print("Sticky IP 1:", r1.json(), "Sticky IP 2:", r2.json())

# 2) Per-request rotation: close the tunnel after each call
r3 = requests.get(
    "https://api.ipify.org?format=json",
    proxies={"http": ROTATING_PROXY_URL, "https": ROTATING_PROXY_URL},
    headers={"Connection": "close"},
    timeout=20,
)
print("Rotated IP:", r3.json())

B. Python (httpx Async) — High-Concurrency Residential Pro Worker

For async pipelines (httpx >= 0.28, use proxy=; on older <0.28 use proxies=), instantiate one httpx.AsyncClient per sticky worker using the URL exported from resi.proxyverge.com:5555 or mobile.proxyverge.com (via Proxy Builder):

import asyncio
import os
import httpx

# Generated in ProxyVerge Proxy Builder (e.g. Residential Pro on resi.proxyverge.com:5555)
RESI_PROXY_URL = os.environ["PV_RESI_PROXY_URL"]
# Example shape: "http://USERNAME:PASSWORD@resi.proxyverge.com:5555"

async def fetch_target(worker_id: int, url: str) -> dict:
    async with httpx.AsyncClient(proxy=RESI_PROXY_URL, timeout=20.0) as client:
        resp = await client.get(url)
        resp.raise_for_status()
        return {"worker": worker_id, "ip": resp.json()}

async def main():
    results = await asyncio.gather(
        fetch_target(1, "https://api.ipify.org?format=json"),
        fetch_target(2, "https://api.ipify.org?format=json"),
    )
    print(results)

asyncio.run(main())

C. Node.js (undici) — Explicit ProxyAgent per Worker

Node's built-in fetch does not read HTTP_PROXY automatically. Using undici's ProxyAgent gives you strict isolation and zero global env surprises:

import { ProxyAgent, fetch } from 'undici';

// Complete URL exported from the ProxyVerge Proxy Builder (e.g. gate.proxyverge.com:10080 or resi.proxyverge.com:5555)
const proxyUrl = process.env.PV_STICKY_PROXY_URL || 'http://USER:PASS@gate.proxyverge.com:10080';

const dispatcher = new ProxyAgent({
  uri: proxyUrl,
  // Keep keep-alive conservative when targeting rotating exits
  keepAliveTimeout: 5_000,
});

try {
  const res = await fetch('https://api.ipify.org?format=json', {
    dispatcher,
    signal: AbortSignal.timeout(20_000),
  });
  console.log(await res.json());
} finally {
  await dispatcher.close();
}

D. Playwright (Chromium) — Per-Context Sticky Isolation

If you launch multiple scraping jobs inside one Chromium process, passing proxy credentials only to chromium.launch() forces all contexts through one exit. In Chromium, pass a placeholder server at launch so each newContext() can bind its own sticky Proxy Builder credentials and cookie jar:

import { chromium } from 'playwright';

const browser = await chromium.launch({
  headless: true,
  // Required in Chromium to allow distinct proxy settings per BrowserContext
  proxy: { server: 'http://per-context' },
});

async function runWorker(workerLabel, username, password) {
  const context = await browser.newContext({
    proxy: {
      server: 'http://gate.proxyverge.com:10080',
      username, // Sticky credential generated for this worker in the Proxy Builder
      password,
    },
  });
  const page = await context.newPage();
  await page.goto('https://api.ipify.org?format=json', { waitUntil: 'domcontentloaded', timeout: 25_000 });
  const text = await page.textContent('body');
  await context.close();
  return { workerLabel, body: text };
}

try {
  const out = await Promise.all([
    runWorker('ctx_1', process.env.PV_STICKY_USER_1, process.env.PV_STICKY_PASS_1),
    runWorker('ctx_2', process.env.PV_STICKY_USER_2, process.env.PV_STICKY_PASS_2),
  ]);
  console.log(out);
} finally {
  await browser.close();
}

4. Troubleshooting Checklist When Exit IPs Behave Unexpectedly

  1. Both state and city selected together: The Proxy Builder treats state/region and city targeting as mutually exclusive—pick one level of granularity (or switch to ASN targeting without state/city).
  2. Keep-alive masking per-request rotation: When using per-request rotation mode, persistent HTTP/1.1 keep-alive tunnels keep routing over the already-opened TCP socket. Set Connection: close or close/recreate pooled connections whenever every single HTTP request must switch exit IP.
  3. Browser media eating GBs: Headless browsers pull fonts, images, and analytics beacons unless blocked (page.route('**/*.{png,jpg,woff2}', route => route.abort())) or shifted onto unlimited-bandwidth Static ISP IPs.
  4. Cloud VM auth friction: If your scrapers run from fixed VPS/VDS hosts, switching Static ISP proxies from user:pass to IP Whitelist eliminates Chromium proxy auth prompts and simplifies container configs.

5. Transparent Pricing Snapshot (If You Need a Unified Sandbox + Production Pool)

All pools on ProxyVerge share one USD wallet balance with crypto checkout (NOWPayments) and instant dashboard builders:

  • Residential Pro (resi.proxyverge.com:5555): $1.40 / GB (non-expiring, starts at 5 GB = $7.00, 190+ countries, country/region/city or ASN, sticky TTL 1–1440 min).
  • Proxy Trio (gate.proxyverge.com): $1.30 / GB (30-day) or $1.95 / GB (non-expiring), starts at 19 GB — shared pool across Residential (148 countries), Mobile (150 countries), and Datacenter (71 countries), HTTP :10080 & SOCKS5 :10800 (+ optional UDP).
  • Mobile 4G/5G Pro (mobile.proxyverge.com): $2.35 / GB (non-expiring, starts at 5 GB = $11.75, 155 countries, carrier ASN targeting, host/port in Proxy Builder).
  • Premium Static ISP: $1.79 / IP (min 5 IPs = $8.95; AT&T $2.75 / IP), unlimited bandwidth, instant HTTP / SOCKS5 / IP Whitelist (up to 20 IPs) switching.
  • Co-located Virginia Compute: AMD EPYC DDR5 NVMe VPS from $32.90/mo (4 vCPU / 8 GB; Ubuntu 24.04 / Debian 11 / Windows Server 2019 at checkout + power controls) and 100 Gbps VDS from $169.00/mo (with self-service OS reinstall) on the same wallet balance.

Happy scraping—and always isolate sticky sessions per cookie jar!

No comments yet. Be the first to comment.