Routing Strategies
Distribute requests across proxy pools using different routing strategies.
Octoprox supports multiple routing strategies for distributing requests across proxy pools:
| Strategy | Description |
|---|---|
round_robin |
Distributes requests evenly across all healthy proxies in order |
least_used |
Routes to the proxy with the fewest transfers open on the gateway serving the request |
random |
Randomly selects a healthy proxy for each request |
sticky |
Routes requests carrying the same -sessid- to the same proxy; requests without one are routed like random |
health_based |
Prefers the proxies with the best success rate and latency on the gateway serving the request, and keeps trying the ones it has too few results for |
Every strategy picks in two steps when a project has more than one connector: first a connector, by its weight, then a proxy inside that connector, by the strategy. A project with a single connector skips the first step.
Strategies run on the gateways, each on its own: round_robin and random keep their position per gateway, least_used counts the transfers open on its gateway and health_based scores what its gateway saw, so nothing is shared between gateways on the request path. Only sticky sessions are shared, through Redis, so a session keeps its proxy whichever gateway the next request reaches.
Connector weights
Each connector has a Weight on its Routing tab (API: routing_config.weight, an integer from 1 to 100, default 1). It is the connector’s share of the project’s traffic relative to the other connectors that can serve the request. Weights are ratios, not percentages: 1 and 3 split requests 25/75, and 2 and 6 do the same.
The share does not depend on how many proxies a connector holds. Before weights, a strategy saw one flat list of proxies, so a pool of ten sessions took ten times the traffic of a connector with one row. That made a dynamic sessions connector, which has exactly one gateway row but unlimited exits, almost invisible next to any pool. With weights, one gateway row and a fifty-slot pool split evenly at equal weights, and you move the split by changing one number.
How a request is placed
- The project’s connectors are narrowed to those that can serve the request: enabled, at least one healthy and non-quarantined proxy, target domain allowed by the connector’s domain filter, and the requested country served (see country routing).
- One of them is picked in proportion to weight. A connector that dropped out in step 1 takes no share, and the remaining connectors split its traffic by their own ratios: with weights 1, 1 and 2, the connector at 2 takes 50%, but if a 1 has no healthy proxy it takes 67%.
- The project’s strategy picks a proxy inside that connector as it always did.
How the strategy performs step 2:
| Strategy | Connector pick | Then, inside the connector |
|---|---|---|
random |
Weighted random draw | Random proxy |
round_robin |
Smooth weighted round robin: weights 3 and 1 give the fixed order A A B A, three A for every B, spread out rather than clumped; a request whose weights exit reputation lowered is a weighted random draw | Proxies cycled in order; each connector keeps its own position |
least_used |
Fewest open transfers on this gateway divided by weight, so weight reads as relative capacity; ties broken at random, by weight | Proxy with the fewest open transfers on this gateway; ties broken at random |
sticky |
The session id is hashed onto a connector, weighted, so a session always lands on the same connector | The session’s proxy; a new session is hashed onto one, see Session IDs |
health_based |
Weighted random draw; weight is not adjusted for health | A random pick among the best-scoring third of the proxies this gateway has at least 10 results for, and every proxy it has fewer for |
Under sticky, a session already bound to a proxy keeps it while that proxy is eligible, whatever the weights say. Weight changes steer new sessions only, and raising one weight moves a proportional slice of new sessions rather than reshuffling them all.
health_based scores a proxy on the requests its gateway sent through it since the gateway started: 60% the share that succeeded, 40% the time to connect to the upstream (full marks at 0 ms, none at 1000 ms). A proxy with fewer than 10 results is always in the draw, so a new proxy, or every proxy on a gateway that just started, is tried before the scores decide. Which proxies are healthy at all is the health checks’ business: every strategy only ever sees proxies whose status is healthy.
Exit reputation and effective weights
Exit reputation works under every strategy rather than as one of its own. In a project whose mode is avoid, a request to a site is placed by effective weights: each connector’s weight times its reputation for the request’s site, from 1 (nothing against it) down. Requests naming no site, and projects in off or record, use the weights as configured.
- A dynamic connector (one with a dynamic-sessions gateway, whose exit changes per request) is weighed by its block rate on the site: its own factor is one less its recent blocked reports per recent request there. At the project’s default Strength of 1 the weight is multiplied by that factor, never under the Lowest factor (×0.1 by default); a higher Strength also weighs it against the best dynamic connector for the request (how). It is kept per requested place, and the finest level of the request’s place with enough requests to tell is used: the city, then its state, then its country. A request naming no place uses its own figure. When even the country has none, the weight stands: there is no figure for all countries to fall back on.
- A connector with IPs (a static list, ISP or datacenter ports, cloud instances, pooled session slots) is weighed by the share of its proxies eligible for the request whose exit IP is not avoided for the site. The avoided ones are dropped before the strategy runs, like resting ones, so a connector left with none takes no share of that site’s requests.
Weights stay relative, so a connector lowered less than the others gains share. Every strategy picks the connector by the effective weights; sticky places only new sessions by them, and a bound session keeps its proxy while it is eligible. round_robin draws the connector at random by them for a request whose weights were lowered, rather than taking it in its fixed order: that order is shared by all the project’s requests, whatever their site, so it could not keep each site’s split. Its other requests keep the order.
Example. A dynamic residential connector at weight 3 and a pool of 20 datacenter IPs in the United States at weight 1 split requests 75/25. On www.google.com the residential connector’s recent record for the United States is 70 blocked reports on 200 requests, so a request there with -cc-us weighs it 3 x 0.65 = 1.95; 10 of the pool’s 20 IPs are avoided for the site, so the pool weighs 1 x 0.5 = 0.5. Those requests split 80/20 (1.95 and 0.5 of 2.45), requests to other sites still 75/25, and the pool’s 10 avoided IPs take none of the site’s requests.
Examples
One pool plus a dynamic residential connector. A datacenter pool with 20 IPs at weight 1 and an Oxylabs residential connector with dynamic sessions at weight 1: half the requests go to the pool (each IP sees 2.5% of the total), half to Oxylabs, each opening a fresh vendor session or reusing the client’s. Set Oxylabs to 3 and it takes 75%.
Two residential vendors. Bright Data at weight 7 and Decodo at weight 3, both dynamic: 70/30, regardless of their slot counts. Under sticky, a given -sessid- always reaches the same vendor, so the vendor session stays stable.
Cheap first, expensive as a slice. ISP proxies at weight 8, a residential pool at 1 and a dynamic mobile connector at 1: 80/10/10. A request with -cc-de for a country the ISP connector has no IPs in skips it, and the other two split that request 50/50.
Two pools of different sizes. Pools of 10 and 30 slots at the default weight split 50/50. Before weights they split 25/75 by row count; set weights 1 and 3 to keep that.
Seeing the split
The Traffic split panel on the Overview and Connectors pages shows, for each connector, its weight, the expected share of untargeted requests under the current weights and health, and, under All traffic, the observed share of every request over the selected window, with a sentence explaining the current setup. Connectors that take no traffic say why (disabled, no healthy proxy). The connector list shows the weight and expected share next to each connector, and the Weight field in the connector editor previews the share while you type. The same numbers are available from GET /api/v1/projects/{project_id}/metrics/traffic-split, see the API reference.
With exit reputation recording, pick a site, and a place for it, to see each connector’s reputation there and the effective share it makes beside the configured one; the API takes them as site and place. The site and place pickers do not narrow the observed share: it counts every request through the connector, whatever its site or place. Requests that carry a country or hit a filtered domain see a narrower set of connectors, so the observed split can differ from the expected one. Observed counts come from the connector’s own metrics history, so they survive proxy rotation. A connector blocked by its traffic limit is listed as over traffic limit and its weight is shared by the others, like a disabled connector’s; with a price per GB the panel also shows what each connector’s traffic in the window cost.
Session IDs
When using the sticky routing strategy, you can control session affinity by embedding a session ID in the proxy authentication username. This allows you to group requests under a specific session, ensuring they are all routed to the same upstream proxy.
Format: <username>-sessid-<session_id>
Examples:
# Without session ID - no affinity, each request is routed like random
Proxy-Authorization: Basic base64(myuser:password)
# With session ID - uses "order-123" for session affinity
Proxy-Authorization: Basic base64(myuser-sessid-order-123:password)
# Hyphenated username works too
Proxy-Authorization: Basic base64(my-project-sessid-abc456:password)
Behavior:
- The
-sessid-delimiter separates the real username from the session ID. The password remains unchanged. - The session ID is the only key the sticky strategy uses. The client’s address is never one: behind a NAT or a load balancer it is shared by every client, and a session should exist only when a client asked for one.
- A session keeps its proxy while it is in use: at least 2.5 minutes, usually 5, after its last request, and every request starts that time again. After a longer gap the next request places the session afresh, as a new session: each of the connector’s proxies holds points on a hash ring, whether it is healthy or not, and the session goes to the first proxy after its own hash that can serve the request. The same session ID therefore lands on the same proxy whenever the same proxies are eligible, and a proxy that is out at that moment moves only the sessions that would have landed on it. A proxy added to the connector takes its share of the sessions placed afresh and leaves the others where they were, except when the connector grows past 16 or 64 proxies, where each proxy’s share of the ring is resized and some sessions move between the others too. Placing a session takes the same time however many proxies the connector has.
- If the proxy a session is bound to stops being eligible (unhealthy, removed, or rate limited without sticky session quarantine), the next request moves the session to another proxy, where it stays while it is in use. A proxy exit reputation avoids for a site moves the session the same way when the project moves refused sessions, and otherwise refuses the session’s requests to that site with a
502(Exit <ip> of this session is avoided for <site>) until the avoid ends; a new session would be served. - To reach one particular proxy rather than whichever one a session lands on, name it with
-prxy-; see Pinning a proxy. - Without a session ID, the sticky strategy picks a connector by weight and a proxy inside it at random for each request, exactly like
random. - This feature only takes effect when the project’s routing strategy is set to
sticky. Other strategies ignore the session ID. - Connectors running a residential or mobile product with dynamic sessions also forward the session to the vendor: the
-sessid-value is hashed into the vendor’s session id, so the same value keeps the same exit IP across requests and gateways, and a request without-sessid-gets a fresh vendor session every time. The whole requested place is part of that hash:-sessid-order-1-cc-deand-sessid-order-1-cc-usare two vendor sessions with two exits, and so are-cc-us-city-austinand-cc-us-city-dallasunder one-sessid-, each kept for as long as the client reuses it, since a vendor does not move a session it has already placed somewhere else. This applies under every routing strategy, not onlysticky. A project that moves refused sessions gives a session whose exit preflight refused a new vendor session, which the same-sessid-keeps from then on. See Dynamic sessions.
Note: The strings
-sessid-,-cc-,-st-,-city-,-prxy-and-tag-are reserved delimiters and should not appear in your project username, in session IDs or in exit report tags.
Pinning a proxy
A client can name the proxy a request goes through. This suits static lists and long-running cloud instances, where a client wants to reach each of a known set of IPs on purpose, rather than trying session IDs until every IP has turned up.
Format: <username>-prxy-<proxy_id>
# Always through proxy 3f2a9c1e-5b7d-4e8f-9a0b-1c2d3e4f5a6b
Proxy-Authorization: Basic base64(myuser-prxy-3f2a9c1e-5b7d-4e8f-9a0b-1c2d3e4f5a6b:password)
Open a proxy on the Proxies page to see its id under Details, with a button that copies it. The same id is the id of its row in GET /api/v1/projects/{project_id}/proxies. With exit headers on, every response also names the proxy it went through in X-Octoprox-Proxy-Id.
Behavior:
- Every routing strategy honours it, and the request never moves to another proxy. When the pinned proxy cannot serve the request, the request fails:
502 Bad Gateway(Proxy <id> is not available for this domain) when the id is not one of the project’s proxies, or the proxy is not healthy, its connector is disabled, or it does not serve the requested place or destination.-cc-,-st-,-city-and the connector’s domain filter apply as on any request.429 Too Many Requestswhile the proxy is rate limited.502 Bad Gateway(Proxy <id> is avoided for <site>) while exit reputation avoids its exit IP for the request’s site.- The connector’s traffic-limit status,
509by default, while its connector is over its traffic limit. - With the preflight check on, an exit that fails the check fails the request instead of another proxy being tried. A dynamic-sessions gateway pinned without
-sessid-is first tried again with a fresh vendor session, as on any request.
- With
-sessid-as well, the sticky strategy does not read or change the session’s binding: the session’s next request without-prxy-goes where the session was. On a dynamic-sessions connector the session still chooses the vendor session, so pinning its gateway row with a-sessid-keeps one exit. - A slot of an “All countries” pool’s country group, which requests without
-cc-never reach, can be pinned without-cc-: it exits in its group’s country. - An id belongs to one proxy row. A static proxy keeps its id until it is deleted. A cloud proxy’s row goes with its instance, so a replaced instance comes back under a new id.
- An id that contains one of the other delimiters, such as a cloud instance whose name holds
-st-, cannot be pinned: the username would be read as two parameters.
Country Routing
A single project can hold connectors that exit from different countries. Instead of maintaining one project per location, clients choose the country per request by embedding a country code in the proxy authentication username, the same way session IDs work.
The project’s Connect page builds the username for any country, state, city and session, and shows which connectors would serve it; see Connecting clients.
Format: <username>-cc-<iso_code>
The code is a two-letter ISO 3166-1 alpha-2 country code and is case-insensitive. uk is accepted as an alias of gb, the ISO code for the United Kingdom, wherever a country is entered: in this suffix, in a connector’s country settings and on a manually added proxy. Anything else (-cc-usa) is answered with 400 Bad Request rather than routed.
Examples:
# Route through proxies serving the United States
Proxy-Authorization: Basic base64(myuser-cc-us:password)
# Combine with a sticky session, in either order
Proxy-Authorization: Basic base64(myuser-cc-de-sessid-order-123:password)
Proxy-Authorization: Basic base64(myuser-sessid-order-123-cc-de:password)
Declaring countries on a connector
Every connector has one Countries setting, on its General (or Infrastructure) tab. It takes zero or more codes, and “Number of proxies” always means per country. What happens then depends on how the provider reaches a country:
| Connector | Countries listed | Countries empty |
|---|---|---|
| Residential and mobile pools (Oxylabs, Bright Data, Decodo, IPRoyal, NetNut) | N sessions are created per listed country right away, geo-targeted in the upstream credentials. Requests for other countries are refused. | N sessions are created without a country. In addition, the first -cc- request for any country creates N sessions geo-targeted to it, on demand (that request waits up to 5 seconds for them), and they stay for later requests. |
| Port-based types that pick IPs from the vendor’s list (Bright Data ISP and datacenter) | N IPs are pinned per listed country right away, chosen from the IPs the zone has in that country. | IPs are pinned in list order; each keeps its reported country for per-proxy matching. |
| Port-based types where each gateway port is pinned to an IP (Oxylabs and Decodo ISP and datacenter) | Gateway ports are scanned in order and only IPs located in the listed countries are kept, N per country. With 5 countries and N = 10 the scan aims for 50 proxies and stops early when the ports start returning failures or IPs already held, or after max_scan_ports ports. |
Ports are taken in order regardless of location; each IP keeps its discovered country for per-proxy matching. |
| Static connectors | The countries the manually added proxies exit from, used for proxies whose own location is unknown. | Each proxy is matched on its own exit country, looked up when it was added (proxy.geo_lookup), set by hand, or refreshed from the Proxies page. |
| Cloud connectors | Optional: makes the region’s instances selectable by country. | Not selectable with -cc-. |
For every port-based type with countries listed, the periodic IP refresh re-reads each proxy’s location. A proxy whose exit moved outside its country is dropped immediately, and the reconciliation that follows the refresh discovers a replacement, so the pool never serves a country it should not.
How a request is matched
Octoprox narrows the project’s healthy proxies before the routing strategy runs, so country routing composes with every strategy and with domain filtering:
- Connectors that list countries only serve the countries they list, and a connector never serves a country it excludes. When connectors reserve the requested country, only they are considered.
- A proxy with a known exit country must match exactly. The exit country is what IP attribution resolved for the proxy’s exit IP from the local IP databases, then the echo endpoint, then the vendor’s claim (list-mode entries, known-IP APIs, the country a slot was provisioned for), which fills only what nothing independent answered. A proxy whose resolved country lies outside its connector’s listed countries is never eligible, whatever was asked.
The project’s two location decisions then read the verdict on the row. With
location_contradicted: refuse, a proxy whose vendor-declared country is contradicted by attribution is not eligible at all; withevidenceit serves on the country the evidence puts it in, and withvendoron the vendor’s claim. Withlocation_unknown: refuse, a claim the sources could not settle or place is left out. A-st-or-city-request reads the row’s state or city verdict the same way. - A proxy with no known country is eligible only through its connector’s list.
- A residential or mobile pool with no countries listed that has no slot group yet for the requested country creates one on the first request:
num_proxiesfresh sessions geo-targeted to that country. The gateway asks a worker for the group and holds the request until the group reaches it through the routing feed, usually within two or three seconds and at most 5, then routes it; when the group does not arrive in time the request is refused as if nothing served the country. Gateways that miss the same country at the same moment get the one group between them. Later requests rotate across that group like any other, and the periodic sync keeps it alive. Pools that list countries are provisioned up front and never expand on demand.
If nothing in the project serves the requested country, the request is rejected with 502 Bad Gateway. Octoprox never silently falls back to another country. What happens when a proxy’s exit turns out not to be where it should, and how that differs between pooled sessions, dynamic sessions and fixed exits, is worked through on Location routing.
Reserved and excluded countries
Weights share a country between the connectors that serve it. Two settings on a connector’s Routing tab say who serves it at all:
- Reserved countries. Requests naming a reserved country go only to the connectors reserving it, split by their weights. When none of them can serve it (disabled, over its traffic limit, every proxy rate limited, or no exit for the state or city asked for), the request fails with the usual status (
502, the traffic-limit status, or429) instead of going to another connector. The502names the connectors the country is reserved for. A connector that lists countries can reserve only listed ones. - Excluded countries. A connector that lists no countries serves every country except these. Requests naming one go to the other connectors, and its exits known to be in one take no traffic at all. A connector that lists countries has nothing to exclude: its list already is the allow-list.
A reservation follows the reserving connector’s domain filter: hosts it refuses go to the other connectors as before. Requests naming no country keep off a reserving connector’s exits in its reserved countries; a dynamic-sessions connector listing countries renders them in its unreserved countries only, and takes none when all of them are reserved. One that lists no countries renders no country for them, so its vendor still picks one.
Example: one vendor for Great Britain, every other country on the rest. Add a connector listing GB and reserve GB on it. -cc-gb requests now go to it alone, other countries never reach it, and requests naming no country keep off it. No weight needs changing.
{
"config": {"countries": ["GB"]},
"routing_config": {"reserved_countries": ["GB"]}
}
The project’s Countries page shows every country a connector lists, reserves or excludes, or has an exit in, with where a request naming it goes now; it also shows any other country and requests naming no country. Opening a country sets each connector’s role for it in one save: Off (off the list, or excluded for a connector listing none), Serves, or Reserved. Turning a country on or off for a connector that lists countries edits its list, so a pool provisions or drops its proxies there. A connector that lists only that country cannot be turned off for it there, since an empty list means every country: disable or edit the connector instead.
State and City Routing
Below the country a request can name a state and a city:
Format: <username>-cc-<iso_code>[-st-<subdivision>][-city-<slug>]
-st-takes the country’s first-level subdivision, whatever it is called locally, as the subdivision part of its ISO 3166-2 code: a US state (nyforUS-NY), a Canadian province (on), a German Land (by), a French region (idf), England (eng). The full code (US-NY) is accepted too. “State” is the word the vendors use; the IP databases report the same first-level subdivision, so a fixed exit in Ontario matches-cc-ca-st-on.-city-takes the city as a slug: lower case, underscores for spaces (new_york,los_angeles,saint_denis). Spaces and hyphens typed instead are turned into underscores. A few spellings of one city are folded into one slug (city_of_londonandnycarelondonandnew_york), and a qualifier in parentheses is dropped, so the IP databases’ district entries (Sofia (g.k. Banishora),London (Soho)) are the city they belong to.- Both need
-cc-. A username with a state or city and no country, a state that is not a subdivision code, or a city with nothing to slug is answered with400 Bad Requestrather than routed anywhere.
# New York City exits
Proxy-Authorization: Basic base64(myuser-cc-us-st-ny-city-new_york:password)
# Any exit in Texas, kept for a session
Proxy-Authorization: Basic base64(myuser-cc-us-st-tx-sessid-order-9:password)
Two kinds of proxy can serve such a request, and a request is never quietly widened to the country:
| Proxy | How it serves a state or city |
|---|---|
| A residential or mobile connector with dynamic sessions | The state and city are rendered into the vendor request, in the vendor’s spelling: Oxylabs and Decodo get the US state as a name (us_new_york), IPRoyal the name without spaces (newyork), Bright Data the ISO code, NetNut the country_state_city triple. A connector whose vendor cannot say what was asked is skipped: Oxylabs, Decodo, IPRoyal and NetNut name only US states, so -cc-gb-st-eng reaches Bright Data alone; NetNut takes a city only together with its state. The Webshare descriptor mirrors a proxy list and targets nothing per request. |
| A fixed exit: static, ISP, datacenter, list-mode and cloud proxies | Matched on where its exit IP is known to be: the state code and city IP attribution resolved from the IP databases, then the echo endpoint, then the vendor’s own word (a city its list or discovery endpoint names), exactly as the country is; or the state and city an operator set by hand on a static proxy (the pin wins). A proxy whose state or city is unknown does not match a request that names one. |
Pooled residential slots (fixed pool of sessions) serve the country only: their sessions were placed by the vendor without a state or city, and nothing is provisioned per city. If nothing in the project serves the place, the request is rejected with 502 Bad Gateway naming it.
Vendors take US states everywhere and other subdivisions only on Bright Data, and cities everywhere; how well they honour a state or city is what the Exit locations pages report per level (see Provider accuracy). Verification below the country needs a city-level IP database loaded.
With the project’s preflight check on, a session whose exit turns out to be somewhere other than the requested country is also refused after one echo request through the selected upstream, unless location_contradicted is vendor: under sticky with 502 Bad Gateway (Exit country mismatch: requested DE, observed FR (...); a state or city that fails is named the same way), under the other strategies by trying another proxy first. A project that moves refused sessions gives a refused session a new exit instead, under every strategy. location_unknown: refuse refuses an exit no source can place as well (Exit country not confirmed, Exit city not confirmed), at every level the request named; when the request named nothing, location_contradicted: evidence holds the exit to the connector’s listed countries rather than to the vendor’s promise, and refuse to the promise itself. An upstream that refuses the echo with a 4xx or cannot be reached fails the request with its own answer (502 Upstream proxy refused the tunnel: ...), once another connector (after a 4xx) or proxy (otherwise) has been tried where the strategy allows; a 5xx or a timeout does so only where the decisions could refuse. An echo that fails past the upstream refuses a place the request named unless both decisions are vendor, and a place the vendor promised under location_contradicted: refuse or location_unknown: refuse (Exit location not checked, echo request failed). The combinations are worked through on Location routing.
Requests without a -cc- suffix are unaffected: they may use any proxy in the project, except the on-demand country groups of all countries pools, which keep serving only the clients that asked for that country.
Other behavior:
- With the
stickystrategy, a session that switches country, state or city is re-bound to a proxy in the new place. - Country groups created on demand are not removed automatically. Delete unused ones from the Proxies page, or list the countries you need on the connector so the sync manages them.
- The Proxies page shows each proxy’s country, and its state and city when known, and the Overview page shows a world map of where the project’s proxies exit from, with healthy and total counts per country. A dynamic-sessions connector has no exit of its own to plot, since the vendor picks one per request, so the map tints the countries its allow-list names, or the whole world when it names none.
Note: The strings
-sessid-,-cc-,-st-,-city-,-prxy-and-tag-are reserved delimiters and should not appear in your project username, in session IDs or in exit report tags.