← all guides

Crawlee session pools and proxy configuration

A framework that has opinions about proxies

Most scraping libraries treat a proxy as a setting. You give them an address and they use it. Crawlee treats a proxy as part of an identity. It groups a proxy, a set of cookies and a health score into something it calls a session, keeps a pool of those sessions, and decides on its own when one should be thrown away.

That’s a genuinely useful design, and it’s also the source of most confusion when people start using Crawlee with their own proxies. The framework makes decisions you didn’t explicitly ask for: which proxy a request goes through, when a session is retired, when a request gets retried on a different identity. If you know what those decisions are, the defaults can do a lot of work for you. If you don’t, you’ll see behaviour that looks random, and it’ll often cost you bandwidth.

This piece looks at how those pieces fit together. It’s the framework-specific companion to our Scrapy behind a rotating pool piece. Scrapy leaves you to write proxy logic in a middleware. Crawlee ships that logic built in, which changes the question from “how do I build rotation” to “do these built-in rules fit my job”.

Crawlee exists for Node.js and, more recently, for Python. The concepts are shared, but option names and some defaults differ between the two, and they’ve changed across versions. We’ll use the JavaScript names since that’s where most existing jobs live, and we’ll flag defaults as “at the time of writing” where it matters. Check the documentation for the version you’ve pinned before you rely on any exact number.

We run proxy infrastructure and production scrapers. The goal here is to explain what the framework does and where its assumptions come from, and then to be specific about where those assumptions mismatch a small job.

What a session means to Crawlee

In Crawlee, a session is a small object that stands for one consistent visitor. It has an id, a cookie jar, a usage count, an error score and an age. When session pooling is on, which it is by default in the crawler classes, every request is sent under some session from the pool.

The point of a session is consistency. Requests made under the same session share cookies, so a site that sets a cookie on the first page sees it returned on the next. And when proxies are configured, requests under the same session go through the same proxy, so the site sees one address with one set of cookies. That pairing is the core idea: an address and its cookies travel together, and they’re retired together.

Sessions have a limited life. Each one tracks how many times it’s been used, how many errors it’s accumulated, and how old it is. When any of those passes a limit, the session is retired and a fresh one takes its place in the pool. A retired session’s cookies are gone, and the next session may go through a different proxy.

The pool itself has a maximum size. The crawler draws a session from the pool for each request, creating new ones until the pool is full and then reusing existing ones. So at any time you might have hundreds of sessions alive, each tied to one proxy, each with its own cookies.

That model fits a large crawl across many pages with a large proxy pool very well. Whether it fits your job depends on the ratio between sessions and proxies, and on how the session lifecycle interacts with the target. Both of those are covered below.

How a proxy gets chosen for a request

Proxies in Crawlee come from a ProxyConfiguration object. The simplest form is a list of proxy URLs:

const proxyConfiguration = new ProxyConfiguration({
  proxyUrls: [
    'http://user:[email protected]:8000',
    'http://user:[email protected]:8000',
  ],
});

You pass that to the crawler, and the crawler asks it for a proxy URL for each request. When sessions are on, the request is made with the session’s id, and the configuration hands out a proxy based on that id. The same session id gets the same proxy URL for as long as the session lives. New sessions are spread across the list.

When sessions are off, the configuration simply rotates through the list request by request. That’s a different behaviour, and it matters: with sessions off, consecutive requests leave from different addresses with no cookie continuity tied to any of them.

For anything more specific, there’s newUrlFunction, which lets you compute the proxy URL yourself:

const proxyConfiguration = new ProxyConfiguration({
  newUrlFunction: (sessionId) =>
    `http://customer-abc-session-${sessionId}:${pass}@gw.example-provider.net:8000`,
});

This is the pattern for gateway-style providers that encode a sticky session in the username. Using Crawlee’s session id inside the provider’s session token lines the two up: one Crawlee session maps to one sticky exit on the provider’s side. The exact username format is provider-specific, so follow your provider’s documentation rather than the placeholder above.

In the request handler, proxyInfo on the crawling context tells you which proxy URL was used for that request. Log it, with the credentials stripped. It’s the fastest way to see what Crawlee is actually doing.

Sessions and proxies need to agree in number

Here’s the mismatch that catches the most people. The session pool has a default maximum size in the hundreds or more (1,000 in Crawlee’s JavaScript version at the time of writing). A small job might have five proxy URLs. Crawlee will happily create hundreds of sessions and spread them across five proxies.

What the target sees, then, is each of those five addresses carrying many different cookie jars at the same time. From a site’s point of view, one address suddenly has dozens of separate visitors, each with its own session cookie, all arriving through the same exit. That’s the opposite of the consistency sessions were meant to create. It’s also exactly the kind of pattern a site’s abuse controls tend to question.

The fix is to size the pool to the proxies you have. With five fixed exits, a pool of five sessions means one session per address:

const crawler = new CheerioCrawler({
  proxyConfiguration,
  sessionPoolOptions: { maxPoolSize: 5 },
  // ...
});

With a rotating gateway and a session token in the username, the proxy pool is effectively as large as the number of session ids you create, so the pool size becomes a statement about how many parallel identities you want. That should be a deliberate number, tied to how much parallel traffic the target reasonably tolerates, not a default.

It’s worth saying the reverse too. If you have a large pool of proxies and a tiny session pool, most of your proxies never get used. That’s less harmful, but it means you’re paying for addresses the crawler isn’t touching.

Either way, the rule is simple: pick maxPoolSize on purpose, based on your proxy list and your target, and check with the proxyInfo logs that the spread matches what you intended.

When Crawlee decides a session has gone bad

A session doesn’t only retire on age. Crawlee retires it early when it thinks something’s gone wrong, and understanding the triggers explains a lot of otherwise mysterious retries.

The first trigger is status codes. The session pool has a list of blocked status codes, which by default includes 401, 403 and 429 at the time of writing. When a response comes back with one of those, Crawlee treats the session as blocked, retires it, and retries the request, which will usually get a different session and so a different proxy.

The second is the error score. Each failed request adds to a session’s score, and successes gradually bring it down. When the score passes a threshold, the session is retired. You can nudge this yourself from the handler with session.markBad(), or end a session outright with session.retire() when you see something the status code doesn’t show, such as a page that returns 200 but contains an error message.

The third is usage. After a set number of requests, a session retires even if it’s healthy. That keeps any one identity from living forever.

There’s also an option on the crawlers, retryOnBlocked, that tries to recognise common block and challenge pages and handle them the same way as a blocked status code.

All of this is designed around one assumption: that when a request looks blocked, the right move is to retire that identity and try again with another. For a large, well-paced crawl across many domains, where an occasional exit has a bad reputation on one site, that’s reasonable. For a small job hammering one site, it can turn a clear signal to slow down into a loop of fresh identities, each of which gets the same answer. The next few sections are about when that assumption fits and when it doesn’t.

Tiered proxies and what they escalate

More recent versions of Crawlee add tiered proxies. Instead of one list, you give the configuration several lists in order, usually from cheapest to most expensive:

const proxyConfiguration = new ProxyConfiguration({
  tieredProxyUrls: [
    [null],
    ['http://user:[email protected]:8000'],
    ['http://user:[email protected]:8000'],
  ],
});

A null entry means no proxy. Crawlee starts requests on the lowest tier and, when it sees errors or blocks for a given domain, moves that domain’s requests up a tier. If things go well on a higher tier, it can try stepping back down later. The tracking is per domain, so one troublesome site doesn’t push every other site onto the expensive tier.

The appeal is obvious. You pay for residential or mobile bandwidth only for the sites that seem to need it, and everything else stays cheap. For a crawl that touches many domains of very different kinds, that can make a real difference to the bill, though how much depends entirely on your mix of targets.

Two cautions. First, starting on a null tier means your own server’s address makes the first requests to every domain. If that isn’t acceptable for your job, for example because you don’t want your infrastructure’s address associated with the crawl at all, don’t put null in the list. Second, escalation is a reaction to blocks, and that’s worth thinking about carefully. A site that returns 429 to a datacenter exit may be telling you that you’re going too fast, and moving to a residential tier at the same speed just makes the same pace more expensive. Tiering is best as a way to match proxy type to site type. It’s a poor substitute for pacing.

Our piece on targets where plain datacenter proxies are still enough is a good companion here, because deciding the starting tier per target by hand is often better than letting escalation discover it for you.

Where the defaults fit a large crawl

It helps to picture the job Crawlee’s defaults were designed for. A crawl across many domains or a large site, tens of thousands of pages, with a substantial proxy pool. Concurrency scaled automatically based on the machine’s load. Occasional blocks on some exits and some pages, spread thinly across the pool.

In that world, most of the defaults make sense together. A large session pool spreads work across many addresses. Blocked status codes retire the occasional unlucky session, and the retry lands on a different exit that’s likely fine. Usage limits stop any single identity from making a disproportionate share of requests. Persisted session state lets a long crawl survive a restart with its sessions intact. Autoscaling keeps the machine busy without overloading it.

The per-domain tier tracking fits this picture too. With hundreds of domains, you really don’t want to hand-tune which ones need which proxy type, and letting the framework learn it is a fair trade.

Even here, a few defaults deserve a look. Automatic concurrency scales to the machine, not to the target. A fast machine will send requests as fast as it can process them unless you cap them. For a crawl that hits any one domain heavily, maxRequestsPerMinute and maxConcurrency are the settings that express how much load you’re willing to put on a site, and they’re worth setting explicitly on every job, large or small.

And persistence can surprise you. Crawlee can save the session pool’s state to its storage and pick it up on the next run. That’s useful for resuming a long crawl, and it can also mean yesterday’s sessions, with yesterday’s cookies and proxy assignments, are back in play today. Check whether your storage is being cleared between runs and whether that’s what you want.

Where the defaults mismatch a small job

Now picture the other common job. One site, a few thousand pages a day, a handful of proxy URLs or a single gateway. This is where most small teams and solo operators start, and it’s where Crawlee’s defaults most often work against them.

The pool size is the first mismatch, covered above. A pool far larger than the proxy list means many identities per address.

The retry-on-block behaviour is the second. With one target, a 429 is the site talking about your overall rate, not about one exit. Retiring the session and retrying immediately on another exit sends the same request again within moments, from a different address, which is neither polite nor effective. On a job like this, it’s usually better to treat blocked responses as a reason to slow the whole crawler down. You can shrink the list of blocked status codes so a 429 isn’t treated as an identity problem, handle it yourself in the error handler with a pause, and lower maxRequestsPerMinute.

The third mismatch is the retry budget. Each retry through a proxy costs bandwidth. A request that gets retried several times on a residential tier, each time receiving a block page, costs several times the bandwidth of a success and delivers nothing. Setting maxRequestRetries low for blocked responses, and alerting when retries rise, keeps that from quietly eating a month’s allowance.

The fourth is tiering. On a single-site job, you already know what kind of site it is. Pick the proxy type once, based on a small test, rather than letting escalation walk up the tiers under load.

None of this means Crawlee is a poor choice for small jobs. Its request queue, storage and crawler classes are useful at any size. It just means the proxy and session settings should be chosen for the job rather than accepted as they come.

Cookies, logins and the session lifecycle

Sessions carry cookies, and that’s where the lifecycle gets interesting for any job that depends on cookie state.

With persistCookiesPerSession on, which is the default for crawlers that support it, cookies a site sets on one response are sent back on the next request under the same session. That’s what makes a multi-page flow work: a consent cookie, a language preference, a region choice, all carried forward.

When a session retires, those cookies go with it. The next session starts fresh. For public pages that’s usually fine, because the first request of a new session just picks up the defaults again. But it has a cost: every new session repeats the first-visit steps, and on sites where the first visit is heavier than later ones, frequent retirement means more bytes per useful page.

For anything behind a login, retirement is more serious. A retired session means a logged-out visitor, and a crawler that retires sessions on every 403 can end up repeatedly logging in, which is exactly the behaviour a site’s account security watches for. If your job uses an account, and you have permission to automate it, keep it to a small, fixed number of sessions, disable automatic retirement on status codes, and handle errors explicitly. Our piece on how long a session should live covers the target-side reasoning for session lifetime.

There’s also the question of what happens when a session’s proxy stops working mid-life. With a fixed proxy list, the session keeps using its assigned proxy until errors retire it. With a sticky gateway, the provider may move the session token to a different exit when the old one drops, and Crawlee won’t know. The session’s cookies then arrive from a new address. Logging proxyInfo alongside the exit address from an occasional echo check is the only way to see that happening.

Reading what the crawler actually did

Because Crawlee makes routing decisions for you, you need visibility into those decisions, especially early on. Three things are worth logging from the start.

First, the proxy used for each request, from proxyInfo, with credentials removed. Paired with the session id, it tells you whether sessions and proxies are lining up the way you intended. If one proxy shows up under dozens of session ids at once, your pool size is too large for your list.

Second, session retirements and their reasons. The crawler’s logs and statistics include retry counts and errors. Adding a line in your error handler that records the status code and session id, along with which proxy carried the request, gives you a clear picture of whether retirements are spread across exits or concentrated on one site. The first suggests bad exits. The second suggests you’re going too fast for that site.

Third, bandwidth per successful record. Crawlee doesn’t bill you, your provider does, so compare the provider’s usage for a run with the number of records the run produced. A run where that ratio climbs is usually one where retries or block pages are growing. That single number catches more problems than any status-code chart, and our piece on costing a job per thousand pages goes into how to work it out.

It’s also worth running one short job with sessions on and one with sessions off, against a test target you control or a site that clearly permits it, and comparing the proxyInfo logs. Seeing the difference in rotation between the two modes makes the configuration much easier to reason about than reading about it.

Crawlee next to Scrapy and hand-rolled code

It’s worth placing Crawlee’s approach next to the alternatives, since many teams arrive with experience of one of them.

In Scrapy, proxy selection is a middleware you write or install. Each request gets a proxy through its meta, and there’s no built-in concept tying a proxy to a cookie jar. You can build that, with a cookie jar per proxy and your own retirement rules, and people do. The benefit is that every rule is yours and visible. The cost is that you have to write them, and it’s easy to get the pairing of cookies and addresses wrong.

In a hand-rolled script with an HTTP client, you have even more control and even less structure. You decide when to switch proxies, what cookies to keep, and when to retry. For a single-site job with a handful of pages, that’s often the clearest option.

Crawlee sits at the other end. The pairing of proxy and cookies is built in, the retirement rules exist before you write any code, and tiering is available with a few lines of config. The benefit is that a lot of good behaviour comes for free. The cost is that behaviour you didn’t choose also comes for free, and you have to go looking for it.

The practical upshot is that Crawlee rewards reading its configuration reference once, carefully, before the first real run. The settings covered here are the ones that decide how your proxies get used: pool size and blocked status codes first, then retries and concurrency caps, then tiering and whether state persists. Everything else is mostly about the crawling itself.

Browser crawlers and the Python port

Everything above applies to Crawlee’s HTTP crawlers, such as the Cheerio crawler, and it carries over to the browser crawlers built on Playwright and Puppeteer with one extra layer to think about.

A browser can’t change its proxy per request the way an HTTP client can. So a browser crawler has to map sessions and proxies onto browser launches or onto isolated pages. Crawlee’s browser pool handles this, and options on the crawler and the pool decide how: whether each page gets its own isolated context, how many pages a browser keeps open, and after how many pages a browser is retired. Those settings interact with the session pool. If a browser is shared by pages from several sessions, and all of them go through that browser’s proxy, you’re back to many identities on one address. Read the browser pool options for your version and check with proxyInfo and an echo page that each session really has its own route.

Browser crawlers also make the bandwidth side of retries worse. A retried request in an HTTP crawler costs one page. A retried request in a browser crawler costs the page plus every script, image and font it loads. Keeping retries on blocked responses low matters more here, not less.

Crawlee for Python follows the same design: a proxy configuration object, a session pool, tiered proxy URLs and the same idea of sessions carrying an address and cookies together. The option names follow Python conventions, so tieredProxyUrls becomes tiered_proxy_urls and so on, and some defaults and features have arrived at a different pace from the JavaScript version. If you’re moving a job between the two, don’t assume a default carried over. Read the Python reference for the version you install, set the important numbers explicitly, and run the same small comparison of logs before the real job.

What none of these settings change

It’s worth being plain about what session pools and proxy tiers can’t do.

They don’t make a crawler invisible, and they don’t guarantee a site won’t block it. A site’s view of a crawler is built from many signals, including the rate and pattern of requests, and the consistency between them. A framework that retires identities quickly on blocks can make the pattern stranger rather than better, since a site sees a stream of short-lived visitors that all behave the same way.

They also don’t replace the decision about whether and how to crawl a site. Robots rules, the site’s published terms, rate limits the site states, whether there’s an official API or data feed, and whether the pages contain personal data you have no business collecting: those are decisions made before the crawler starts. No session setting makes an inappropriate crawl appropriate.

What these settings do well is manage the mechanics of identity and routing consistently, so you don’t have to write that logic yourself. Used with a sensible pace, a pool sized to your proxies, and retries that back off rather than escalate, they make a crawler more predictable and cheaper to run. That’s worth having. It’s just a narrower benefit than some tutorials suggest.

Setting up a Crawlee job on Monday

If you’re starting a Crawlee job, or reviewing one that’s already running, here’s the short version.

Decide whether you want sessions. For almost any job with proxies, you do, because it keeps cookies and addresses paired. Leave it on, and understand that it changes how proxies rotate.

Size maxPoolSize to your proxies. With a fixed list, one session per proxy is a good start. With a sticky gateway, use newUrlFunction to put Crawlee’s session id into the provider’s session token, and choose the pool size as the number of parallel identities you’re comfortable presenting to the target.

Set maxRequestsPerMinute and maxConcurrency explicitly, based on what the target can reasonably handle, not what your machine can push.

Review the blocked status codes and the retry count. On a single-site job, treat 429 as a reason to slow down rather than to switch identity, and keep retries on blocked responses low.

If you use tiers, decide whether a null tier is acceptable, and consider setting the starting tier by hand for targets you already understand.

Check whether session state persists between runs, and whether you want it to.

Log proxyInfo, session ids, retirement reasons and bandwidth per record from the first run.

Write the chosen numbers into the job’s config with a one-line reason for each, so the next person to touch the crawler knows which values were deliberate and which were left at the framework’s defaults. That note is also what makes an upgrade safe. When Crawlee changes a default in a new release, a job that sets its important values explicitly keeps behaving the same, and a job that relied on defaults can change how it uses your proxies without a single line of your code changing.

Then run small, read the logs, and adjust. The framework is doing a lot on your behalf. The first run is where you find out exactly what.

For more on rotation, sessions and choosing proxy types per target, the rest of our guides are on Proxy Scraping.

Get new guides and videos first — join the Telegram channel.

proxies
Need proxies that survive the block wall?

Singapore Mobile Proxy runs real 4G/5G mobile IPs on rotating SIMs — the carrier-grade addresses most of these targets still trust.

see plans →
read on
More scraping guides

The rest of the field manual: target-site playbooks, library walkthroughs, provider reviews, and anti-bot troubleshooting.

browse all guides →