Part 9 · Blueprint 52
Distributed Web Crawler
16 min reading · Sources · Editorial review pending
More workers can overload a host or repeatedly fetch duplicate URLs.
Page details
Published date · Last edited:
Draft edition. Editorial review and supplementary reading recommendations are still being completed.
Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Message Queues & Event Streams: Kafka vs. RabbitMQ, Database Sharding & Consistent Hashing, Rate Limiting Algorithms: Token Bucket to Sliding Window.
Sixty-second mental model
Problem: More workers can overload a host or repeatedly fetch duplicate URLs.
Use: Coordinate host admission and revalidate changing destinations.
Design boundary: Fetch a selected web corpus under a declared crawl policy. The frontier owns URL eligibility; host admission owns politeness across workers. Normalization, redirects and discovered links affect both duplicate work and security. Exclude the complete search-ranking product.
Layer 1 · Intuition
Hypothetical scenario: Northwind is designing web crawling. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one fetch means and which component owns the crawl frontier.
Think of a polite shared calendar of websites to visit. Separate the requester from crawl frontier, then identify the retained evidence needed after failure.
- Authority
- The entitled state owner.
- Invariant
- A rule preserved across concurrency and failures.
Architecture and worked reasoning
Design boundary: Fetch a selected web corpus under a declared crawl policy. The frontier owns URL eligibility; host admission owns politeness across workers. Normalization, redirects and discovered links affect both duplicate work and security. Exclude the complete search-ranking product.
Responsibilities on the request path
Domain interface and access patterns
POST /crawl-jobs → job_id; internal lease-next(host_budget) → url_id, lease_epoch; GET /crawl-jobs/{id} → bounded progress
frontier(job_id, canonical_url, state, next_eligible_at, lease_epoch); hosts(host_key, next_fetch_at, active_budget); fetches(url_id, attempt_id, resolved_destination, response_ref). Unique URL policy and host policy solve different constraints.
Workload and limiting resource
Choose 1,000,000 pages/day: average fetch rate is 1,000,000 / 86,400 ≈ 11.57/s. At a selected 2-second mean occupied fetch time, average concurrent fetch work is about 23.15 slots under stable-flow assumptions. A per-host limit of one request/second still caps one hot host even if the global pool has many idle slots. At 100 KB/page, raw daily payload is 100 GB.
Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.
Mutation or publication path
- Normalize and deduplicate a discovered URL under the selected equivalence rule.
- Reserve a host-scoped fetch slot and lease a frontier item.
- Store response metadata/content and schedule discovered links or revisits.
Observation and recovery path
- Inspect fetch status and next eligible time.
- Resolve redirect destinations through the same network/security policy.
- Read a versioned fetched object rather than assuming a URL is immutable.
Failure that changes the decision
Hypothetical scenario: A redirect changes a public hostname to an internal address. Revalidate resolved destinations and redirect hops; checking only the submitted URL is insufficient against server-side request forgery.
Attempt this decision before reading the explanation
Can each worker independently sleep one second to enforce host politeness?
No. Ten workers can still send ten requests in that second. Coordinate host-scoped eligibility or allocate a bounded shared policy, and preserve that limit through retries and lease recovery.
Supporting mechanism analysis
Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.
Hypothetical scenario. Northwind wants searchable public supplier documentation. Dev begins with a queue of discovered links. Priya opens a page that leads to more calendar URLs and another host, then asks when that queue is allowed to stop growing.
Maya: “Which candidates belong to the approved collection, and when are they eligible to fetch?”
Build a frontier that connects discovery provenance, host scheduling, fetching and document identity. Limit the case to approved public HTTP documents; private accounts, login automation and arbitrary scripts remain excluded. This workload does not inherit feed or chat rates.
Before you continue: Does a discovered URL automatically become work the crawler must complete?
That lets input structure determine unbounded coverage and demand. Discovery needs eligibility, identity and scheduling rules before it becomes an accepted fetch obligation.
This makes coverage and host-limited demand explainable. A delivery queue can carry eligible work without being the only memory of what the crawler has already considered.
A frontier is retained work with policy attached. Each candidate needs an identity, discovery provenance, eligibility state and a next eligible fetch time. A FIFO queue alone cannot express a host-specific pause or distinguish an already fetched document from a newly discovered address. Treat the queue as a delivery mechanism for frontier records, not the only authoritative memory.
Start with an explicit host allowlist and a collection budget. Normalize URLs only through transformations whose meaning you understand. Removing fragments from an HTTP fetch identity is different from deleting query parameters that might select a different document. Keep the original discovered URL for diagnosis alongside the chosen normalized key.
URL deduplication answers whether this fetch candidate is already known. Content deduplication answers whether fetched representations match under a selected comparison. Two addresses can return identical bytes, and one address can change over time. Retain a fetch timestamp and representation identity rather than overwriting those distinctions with one undated body.
Bound both concurrent work and response consumption. Connection deadlines alone do not prevent an endless body, oversized decompression or excessive parser memory. Apply byte, decompressed-size and processing limits, and record the reason for truncation. A partially fetched body must not masquerade as a complete document in the search index.
After a successful fetch, store the representation and metadata durably, then publish an indexing obligation through a recoverable transition. Discovered links return through the same admission rules. They do not inherit permission from their referring page. This closes the loop without allowing the parser to bypass the scheduler.
Hypothetical scenario. The frontier stores canonical fetch candidates under host queues. A scheduler chooses a due host, claims its current generation and admits one URL according to the declared politeness interval. The next-allowed time is a shared host policy, not a separate timer for every worker.
URL normalization removes only equivalences the design can justify. Host aliases, redirects and query parameters can change identity or meaning; two different URLs can return identical content, while one URL can change over time. Keep canonical URL identity, host-budget identity and content digest separate.
Reassignment must fence the old scheduler at the actual fetch-admission boundary. A stale worker that continues fetching can violate the host budget even if its results are later rejected. If the transport cannot enforce such a fence directly, route starts through a current shared admission authority. Bound frontier growth, redirect depth, response size and parser work so discovery cannot consume unbounded resources.
Hypothetical worked example. Select 1,000 approved hosts and one fetch start per host every ten seconds, with no overlap within a host. The policy ceiling from starts alone is 1,000 ÷ 10 = 100 fetches per second. It is not a measured throughput: slow hosts, robots restrictions, failures and exhausted frontiers lower it.
Select a mean complete payload of 100,000 bytes. At that ceiling, payload demand is 100 × 100,000 = 10,000,000 bytes per second, or ten decimal MB per second. For a selected one-hour run, 60 × 60 = 3,600 seconds, so the payload subtotal is 10,000,000 × 3,600 = 36,000,000,000 bytes, or 36 GB. Storage replicas, indexes and protocol traffic are excluded.
Now suppose each completed page discovers twenty candidate links. At one hundred completions per second, discovery yields 100 × 20 = 2,000 candidate observations per second. If selected admission rules retain one hundred fifty distinct eligible candidates per second while the fetch stage completes one hundred, frontier growth is 150 − 100 = 50 candidates per second. Over one hour that is 50 × 3,600 = 180,000 additional candidates. A bounded collection needs admission or prioritization, even though the fetch workers are healthy.
RFC 9309 specifies the Robots Exclusion Protocol , including matching, retrieval errors and caching. It explicitly distinguishes these rules from access authorization. Implement the actual applicable user-agent rules, then apply Northwind’s additional collection policy. A robots allowance is not a credential, a license or proof that every destination is safe.
Record which policy result governed a fetch. Cached policy has an age and retrieval outcome; do not silently convert an unreachable policy service into unrestricted crawling. The service can choose a stricter pause policy while retaining the protocol evidence needed to explain that choice.
Hypothetical failure scenario. A supplier calendar exposes a next-month link indefinitely. Every address is syntactically valid and every response is small. The crawler keeps adding future months until lower-priority documentation waits behind an expanding host frontier. Extra fetch workers do not solve the unbounded admission rule.
Use this architecture when a declared public-document collection needs controlled refresh and searchable provenance. For a small supplier set, a database-backed frontier and modest worker pool can be easier to inspect than a distributed crawler framework. Choose a framework when its actual scheduling and recovery model match the requirements, not because the word crawler implies global scale.
Do not confuse an empty ready queue with completion: delayed candidates, failed policy retrieval and deferred hosts can remain. Report admitted, eligible, fetched, indexed, rejected and postponed states separately. The search product should show when evidence was fetched rather than claiming that all supplier content is current.
Layer 3 · Internals
A crawler's frontier owns the next eligible fetch for a URL, while host-level admission prevents many workers from independently overwhelming the same destination. Normalize URLs conservatively: removing a query parameter without understanding the site can merge distinct resources. Content hashes can detect identical fetched payloads, but do not replace URL identity, freshness or authorization policy.
Robots.txt communicates rules to cooperating crawlers under RFC 9309; it is not an access-control mechanism. Fetchers must also validate redirects, resolved addresses, response size and decompression limits. A URL approved before queuing can resolve somewhere different when fetched. Revalidate the actual destination at connection time and each relevant redirect to avoid turning the crawler into an internal network client. Persist fetch attempts and observations separately from the next scheduled obligation. An HTTP success response can still contain an error page, unsupported media or a maliciously large document, so content processing needs its own bounded acceptance rule.
Trade-offs and limits
| Approach | Provides | Requires |
|---|---|---|
| Host-partitioned frontier | Makes politeness and per-host concurrency easier to enforce. | Popular hosts can dominate a partition's backlog. |
| Globally shared work queue | Spreads independent fetches across workers. | Host admission still needs coordinated state outside blind dequeue. |
Recovery decision
Hypothetical scenario: A redirect changes a public hostname to an internal address. Revalidate resolved destinations and redirect hops; checking only the submitted URL is insufficient against server-side request forgery.
No. Ten workers can still send ten requests in that second. Coordinate host-scoped eligibility or allocate a bounded shared policy, and preserve that limit through retries and lease recovery.
Write your design before revealing the review
Can each worker independently sleep one second to enforce host politeness?
Drafts and self-review are stored only in this browser. They are separate from reading completion.
Compare your decision
No. Ten workers can still send ten requests in that second. Coordinate host-scoped eligibility or allocate a bounded shared policy, and preserve that limit through retries and lease recovery.
A redirect changes a public hostname to an internal address. Revalidate resolved destinations and redirect hops; checking only the submitted URL is insufficient against server-side request forgery.
Check your understanding
Can each worker independently sleep one second to enforce host politeness?
No. Ten workers can still send ten requests in that second. Coordinate host-scoped eligibility or allocate a bounded shared policy, and preserve that limit through retries and lease recovery.
How would you recover from this failure: A redirect changes a public hostname to an internal address. Revalidate resolved destinations and redirect hops; checking only the submitted URL is insufficient against server-side request forgery.
Start with the exact boundary that failed. Normalize and deduplicate a discovered URL under the selected equivalence rule. Reserve a host-scoped fetch slot and lease a frontier item. Store response metadata/content and schedule discovered links or revisits. Then recover evidence through the observation path: Inspect fetch status and next eligible time. Resolve redirect destinations through the same network/security policy. Read a versioned fetched object rather than assuming a URL is immutable. Preserve the distinction between a confirmed state change and an unavailable response.
Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?
Choose 1,000,000 pages/day: average fetch rate is 1,000,000 / 86,400 ≈ 11.57/s. At a selected 2-second mean occupied fetch time, average concurrent fetch work is about 23.15 slots under stable-flow assumptions. A per-host limit of one request/second still caps one hot host even if the global pool has many idle slots. At 100 KB/page, raw daily payload is 100 GB. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Fetch a selected web corpus under a declared crawl policy. The frontier owns URL eligibility; host admission owns politeness across workers. Normalization, redirects and discovered links affect both duplicate work and security. Exclude the complete search-ranking product.
Which component in this topology could be removed from a smaller first deployment?
URL frontier, Host scheduler, Fetch workers, Content store name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Normalize and deduplicate a discovered URL under the selected equivalence rule.
What evidence must a caller have before relying on the observation path?
Inspect fetch status and next eligible time. Resolve redirect destinations through the same network/security policy. Read a versioned fetched object rather than assuming a URL is immutable. No. Ten workers can still send ten requests in that second. Coordinate host-scoped eligibility or allocate a bounded shared policy, and preserve that limit through retries and lease recovery.
45-minute interview rubric
- 00–05: scope fetch and crawl frontier.
- 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
- 12–28: draw crawl frontier, numbered writes and reads.
- 28–40: challenge recovery: Coordinate host admission and revalidate changing destinations.
- 40–45: defend url_id placement, observations and remaining assumptions.
Go deeper
- RFC 9309: Robots Exclusion Protocol · Primary document · www.rfc-editor.org. Coordinate host admission and revalidate changing destinations. Verified 2026-10-26.
Decision log
Coordinate host admission and revalidate changing destinations.
Preserve fetch identity and crawl frontier ownership.
Revisit changed workload, observations or recovery objectives.