A polite web crawler is designed around restraint: it checks a site’s published crawling instructions, requests only what it needs, waits between requests, handles server feedback, and avoids repeating work. This guide presents a repeatable workflow for estimating crawl cost, choosing safe limits, configuring caching, and deciding when your crawler needs to be recalculated.
Overview
Web crawling is not only an extraction problem. It is also a traffic-management problem. A crawler that discovers too many URLs, opens too many connections, or retries failures aggressively can create unnecessary load and produce unreliable results. A crawler that is too cautious may take longer than the project allows or fail to collect enough data.
The goal is to make those trade-offs explicit. Before writing selectors or parsing page content, define the scope of the crawl, inspect the target site’s robots.txt file, identify the URLs that are actually relevant, and set a request budget. A useful budget includes:
- Maximum URLs: the number of distinct pages the job may request.
- Concurrency: the number of requests that may be active at once for a host.
- Request rate: the average number of requests sent during a time interval.
- Retry limit: how many additional attempts are allowed after a failure.
- Runtime: the maximum duration or scheduled window for the job.
- Storage budget: the amount of HTML, assets, metadata, and logs retained.
These limits make a crawler easier to operate and audit. For extraction design, see the guide to robust scraping selectors. If the site offers a suitable data endpoint, compare it with HTML access before crawling: HTML scraping versus API access explains the decision points.
How to estimate
Start with a simple crawl-time estimate. If a job requests N pages at an average interval of D seconds, a sequential estimate is:
Estimated request time = N × D
For example, a 2,000-page crawl with an average delay of 1.5 seconds has a request interval estimate of 3,000 seconds, or about 50 minutes. This is only a planning figure. DNS lookup, connection setup, response time, parsing, retries, redirects, throttling, and pauses between batches can all increase the actual runtime.
For a crawler using limited concurrency, a more useful approximation is:
Estimated request time ≈ (N × average response cycle) ÷ effective concurrency
Use effective concurrency rather than the configured maximum. If five workers are configured but connection delays, host limits, and backoff usually leave three workers active, estimate with three. Keep a separate allowance for retries:
Total request attempts = unique URLs + expected retry attempts
Do not treat retries as free capacity. A temporary server error, timeout, or rate-limit response can multiply traffic if every worker retries immediately. Use bounded retries with increasing backoff, and stop retrying when the response indicates that continuing would be unhelpful. The practical patterns are covered in reliable scraping requests.
Estimate storage as well. If each saved response averages S kilobytes and you retain N responses, the raw response estimate is N × S. Add room for headers, extracted records, screenshots or assets if used, logs, and duplicate versions. A cache can reduce repeated network requests, but it does not eliminate the need to plan storage and expiration.
Inputs and assumptions
1. Read robots.txt before discovery
Request the target host’s /robots.txt file before crawling. Parse the rules for the user-agent your crawler identifies as, and apply the relevant allow and disallow directives to candidate URLs. Treat the file as one part of your operating policy: also check the site’s published terms, documentation, contact guidance, and any available API instructions. When the rules are ambiguous, narrow the crawl or ask the site operator for clarification.
Cache the fetched robots file for the duration of a crawl, record when it was retrieved, and refresh it on a schedule appropriate to the project. If it cannot be fetched, do not silently assume that every URL is available. Pause, use a conservative fallback, or require an explicit operator decision.
2. Define URL scope
Set an allowed host list, path prefixes, schemes, and content types. Normalize URLs before deduplication by handling fragments, obvious tracking parameters, repeated slashes, and equivalent trailing-slash forms according to the site’s structure. Be careful with query parameters: removing all parameters can merge distinct pages, while keeping all parameters can create an effectively unbounded crawl.
Prefer known entry points, sitemaps, pagination limits, and targeted link patterns over unrestricted discovery. Give every crawl a maximum URL count and a maximum depth, even if the initial scope appears small.
3. Choose rate and concurrency conservatively
Use one host-aware limiter rather than allowing each worker to sleep independently. A shared limiter makes the combined request rate visible. Begin with low concurrency and a measurable delay, then increase only when the site’s responses, project requirements, and published guidance support doing so. Avoid parallel requests to the same host when sequential access is sufficient.
Honor response signals. A successful response does not necessarily mean that more traffic is appropriate, and a rate-limit response should trigger a pause or backoff rather than an immediate retry loop. Set connection and read timeouts, cap redirect hops, and record status codes so an operator can see whether the crawl is healthy.
4. Cache and checkpoint
Use a cache keyed by the normalized request URL and relevant request parameters. Store response metadata, retrieval time, status, and a content hash when practical. A cache lets development runs reuse pages instead of repeatedly contacting the origin. Checkpoint the queue and extracted results so a process restart does not begin from the first URL.
For recurring jobs, consider conditional requests where supported, and use incremental crawling to visit pages that are new or likely to have changed. The incremental scraping workflow covers deduplication and resume behavior.
Worked examples
Example A: a small documentation crawl
Suppose a documentation section contains 600 in-scope URLs. You configure one worker, an average request interval of 2 seconds, a maximum of two retries, and a response cache. The baseline interval estimate is 600 × 2 = 1,200 seconds, or 20 minutes. If you expect 5% of requests to require one retry, add approximately 30 request attempts. At the same average interval, that adds about 60 seconds before accounting for backoff and response time.
The operational plan could therefore reserve at least 25 to 30 minutes, use a strict host and path allowlist, and save each response immediately. If the crawl is interrupted after 350 pages, the checkpoint and cache should allow it to resume near the next unprocessed URL.
Example B: a larger catalog with repeated updates
Assume a catalog has 20,000 candidate URLs but only 3,000 are needed for a weekly price or availability check. A full crawl would consume more requests than the task requires. Instead, create an initial bounded crawl, record canonicalized URLs and content hashes, and use an incremental list for later runs. If 400 URLs are added or changed between runs, the recurring budget is based on those 400 pages plus a small validation sample, not the entire catalog.
Monitor the result for status-code changes, queue growth, duplicate URLs, cache-hit rate, average response time, and retry volume. A sudden increase in 429 responses, timeouts, or empty documents is a reason to reduce traffic and investigate, not simply to add workers.
When to recalculate
Recalculate the crawl budget whenever an input changes. This includes adding a domain, expanding path scope, changing URL-parameter rules, increasing concurrency, shortening the request delay, or adding assets such as images and scripts. Recalculate after a site redesign, a new pagination pattern, a change in authentication, or a switch from HTML pages to an API.
Review the estimate after the first controlled run using observed values: unique URLs, total attempts, response-time distribution, status-code counts, cache hits, bytes transferred, and actual runtime. Replace assumptions with these measurements, but do not increase traffic automatically just because the first run completed quickly. The site’s instructions and your agreed operating limits remain constraints.
Before each scheduled crawl, use this checklist:
- Confirm the host, scope, user-agent, and current robots.txt handling.
- Verify the URL cap, depth cap, concurrency, delay, timeout, and retry limits.
- Confirm that cached responses and checkpoints are available.
- Run a small sample and inspect status codes and extracted output.
- Stop or slow the job when server errors, rate-limit responses, or unexpected traffic appear.
- Validate the output and log the final request count, runtime, and failures.
For ongoing quality checks, pair the crawler with fixtures, schema checks, and change detection. A polite crawler is not a one-time setting; it is an operating workflow that should be reviewed whenever its scope, schedule, or observed behavior changes.