Glossary
Request queue: the to-do list behind every crawler
A request queue stores the pages a crawler has discovered but not yet fetched, together with the state needed to retry, prioritize and skip duplicates.
Why a crawler needs one
A crawl grows as it runs. Each fetched page yields new links, and those links must be stored somewhere until a worker is free. A plain in-memory list works for a hundred URLs; for a hundred thousand you need a structure that survives restarts, avoids fetching the same page twice and remembers how many times each request has failed. That structure is the request queue.
What each entry holds
Treat a queue entry as a small record, not just a URL string.
- Unique key, usually the normalized URL (lowercase host, sorted query parameters, no fragment), used for deduplication.
- Method and body, because a POST search with different filters is a different request from the same URL with a GET.
- Retry count and the last error, so a page that keeps failing is eventually dropped instead of retried forever.
- Priority or depth, which controls order (see breadth-first crawling).
- User data such as the category name or the page number in a paginated list.
Storage choices
For a single machine, SQLite or a local file based queue is enough and easy to inspect. For several workers, Redis lists or sorted sets, a database table with row locking, or a message broker such as RabbitMQ give you shared state. Libraries like Crawlee include a persistent queue, and Scrapy has a scheduler with disk persistence and a duplicate filter.
Retries without loops
A failed request goes back into the queue with its counter raised and a delay that grows each time (see exponential backoff). Classify the failure before requeueing: a timeout or a 503 is worth another try, a 404 is not, and a 403 from bot protection needs a different action, not just more attempts. After a fixed number of tries, move the entry to a dead letter list you can review by hand.
Parking pages that hit a challenge
When a worker receives a challenge page instead of content, it should not block while the challenge is handled. A clean pattern is to mark the entry as waiting, submit a task to GateSolver, and let the worker pick up other URLs. A separate loop polls the task every few seconds; once the answer arrives (a Turnstile token typically comes back under 3 seconds), the entry returns to the front of the queue with the token or cookie attached. If the task fails, it costs nothing and the entry follows the normal retry rules.
// a queued request that is waiting for a solved token
const entry = {
key: "GET https://shop.example/list?page=7",
retries: 1,
state: "waiting_token",
taskId: "8f1c2b7a", // returned by createTask
depth: 2
};
Keeping the queue healthy
Watch three numbers: pending entries, entries in flight and entries in the dead letter list. A pending count that grows without limit usually means the crawl scope is too wide, for example following calendar links or session IDs that make every URL look new. Tighten the normalization or add a filter, and the queue stops ballooning.
Common questions
How do I stop a crawler from fetching the same page twice?
Normalize each URL into a unique key and keep a set of keys you have already queued. Skip any new link whose key is already present.
Where should a request queue be stored?
SQLite or files for one machine, and Redis, a database or a message broker when several workers share the crawl.
How many times should a failed request be retried?
Three to five attempts with growing delays is a common choice, after which the entry moves to a list for manual review.
Should a worker wait while a CAPTCHA is being solved?
It does not have to. Park the entry, keep working on other URLs and requeue it when the token arrives.
Why does my queue keep growing?
Usually the crawler follows links that create endless unique URLs, such as calendars or session parameters. Filter or normalize them.
Keep reading
- Breadth-first crawlingVisiting every link one level at a time versus diving deep down one path, and which crawl order suits which job.
- ConcurrencyRunning many requests or solving tasks at the same time, and how per host limits and backpressure keep it under control.
- CrawleeAn open source crawling library for Node.js and Python that bundles queues, retries, sessions and browser or HTTP crawlers.
- Handling several CAPTCHAs in one flowSolve several CAPTCHAs in one journey: order the steps, start independent tasks in parallel, keep answers fresh and pay from one balance.