v1.8.91-d84675c
← Back to Hex Proxies

Sticky Session Best Practices

Last updated: April 2026

By Hex Proxies Engineering Team

Master sticky proxy sessions with Hex Proxies. Understand when to use sticky vs rotating sessions, how to manage session identifiers, and patterns for multi-step workflows.

intermediate15 minutesbest-practices

Prerequisites

  • Hex Proxies account
  • Basic understanding of HTTP sessions and cookies

Steps

1

Identify stateful workflows

Determine which flows require the same IP across multiple requests (login, checkout, forms).

2

Generate session identifiers

Create unique session IDs using UUIDs or random strings. Include a descriptive label.

3

Configure the proxy URL

Append -session-IDENTIFIER to your username in the proxy URL.

4

Implement the workflow

Use the same proxy URL for all requests within the stateful flow.

5

Verify IP consistency

Check the exit IP at the start and end of the workflow to confirm the session held.

6

Expire and rotate

Create new session IDs for new workflows. Do not reuse old identifiers.

Sticky Session Best Practices

Sticky sessions maintain the same proxy IP across multiple requests. This is essential for workflows that rely on server-side state, such as login flows, shopping carts, or multi-page form submissions. Hex Proxies supports sticky sessions across its 10M+ residential and 250K+ ISP proxy pools.

How Sticky Sessions Work

Append a session identifier to your proxy username. The gateway maps that identifier to a specific exit IP and routes all matching requests through it:

Username format: YOUR_USERNAME-session-IDENTIFIER
Example: user123-session-checkout-flow-001

When to Use Sticky Sessions

| Scenario | Session Type | Duration | |----------|-------------|----------| | Login + authenticated browsing | Sticky | 5-30 minutes | | Shopping cart + checkout | Sticky | 10-15 minutes | | Multi-page form submission | Sticky | 5-10 minutes | | API with rate limits per IP | Sticky | Varies | | Stateless scraping | Rotating | N/A | | Price comparison | Rotating | N/A |

Implementation Patterns

#### Python: Session-Aware Scraping

import requests

class StickyProxyScraper: def __init__(self, base_user, password): self.base_user = base_user self.password = password self.gateway = "gate.hexproxies.com:8080"

def create_session(self, label="default"): session_id = f"{label}-{uuid.uuid4().hex[:8]}" proxy_url = f"http://{self.base_user}-session-{session_id}:{self.password}@{self.gateway}" session = requests.Session() session.proxies = {"http": proxy_url, "https": proxy_url} session.timeout = 30 return session

def login_and_scrape(self, login_url, target_url, credentials): session = self.create_session("login")

# Login (same IP) login_resp = session.post(login_url, json=credentials) if login_resp.status_code != 200: raise Exception(f"Login failed: {login_resp.status_code}")

# Scrape authenticated pages (same IP) data_resp = session.get(target_url) return data_resp.json()

scraper = StickyProxyScraper("YOUR_USERNAME", "YOUR_PASSWORD") data = scraper.login_and_scrape( "https://example.com/api/login", "https://example.com/api/data", {"user": "me", "pass": "secret"} ) ```

#### Node.js: Session Management

import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch from 'node-fetch';

function createStickyAgent(baseUser, password, label = 'default') { const sessionId = `${label}-${crypto.randomBytes(4).toString('hex')}`; const proxyUrl = `http://${baseUser}-session-${sessionId}:${password}@gate.hexproxies.com:8080`; return new HttpsProxyAgent(proxyUrl); }

const agent = createStickyAgent('YOUR_USERNAME', 'YOUR_PASSWORD', 'checkout');

// All requests through this agent use the same IP const loginResp = await fetch('https://example.com/login', { method: 'POST', agent, body: JSON.stringify({ user: 'me', pass: 'secret' }), headers: { 'Content-Type': 'application/json' }, });

const dataResp = await fetch('https://example.com/dashboard', { agent }); console.log(await dataResp.json()); ```

Session Lifecycle Management

  • **Generate unique IDs**: Use UUIDs or random hex strings. Never reuse session IDs across unrelated workflows.
  • **Label sessions**: Include a human-readable label (e.g., "checkout", "login") for debugging.
  • **Expire sessions**: Create new session IDs after the workflow completes. Do not hold sessions indefinitely.
  • **Handle IP changes**: If the session IP changes unexpectedly, create a new session and restart the workflow.

Common Pitfalls

  • **Reusing session IDs across workflows**: This can cause unrelated requests to share an IP, leading to unexpected blocks.
  • **Holding sessions too long**: Extended sessions can trigger rate limits or IP reputation degradation.
  • **Mixing sticky and rotating in the same flow**: The login request and subsequent authenticated requests must all use the same session ID.
  • **Not checking IP consistency**: Verify the exit IP at the start and end of critical workflows.

Tips

  • *Always use unique session IDs -- reusing IDs across workflows causes unexpected IP sharing.
  • *Include a descriptive label in the session ID (e.g., "checkout-abc123") for easier debugging.
  • *Keep sticky sessions short -- 5 to 30 minutes depending on the workflow.
  • *Verify the exit IP at both the start and end of critical flows to detect unexpected session drops.

Ready to Get Started?

Put this guide into practice with Hex Proxies.

Cookie Preferences

We use cookies to ensure the best experience. You can customize your preferences below. Learn more