Designing a Distributed, Politeness-Governed Web Crawler
Crawling one billion web pages per month requires distributed URL frontier scheduling, strict per-domain politeness throttling, Bloom filter deduplication, and robust protection against infinite spider traps.
Frontier Geometry & Storage Footprint
The web contains hundreds of billions of URLs. The crawl frontier must store, deduplicate, and prioritize prospective links without exploding RAM or thrashing disks.
Bandwidth & Document Ingestion Math
- 1. Average Page Size: 100 KB raw HTML (excluding client media assets). 400 pages/s * 100 KB = 40 MB/s (320 Mbps) sustained inbound network bandwidth.
- 2. Raw Storage Volume: 1 billion pages * 100 KB = 100 TB raw HTML / month. Compressed via Zstandard (4:1 ratio) = 25 TB monthly storage appended to S3.
- 3. Link Expansion Factor: Each crawled page yields an average of 40 outbound links. 1B pages generate 40 billion discovered URLs that must pass through deduplication filters.
URL Deduplication (Bloom Filter Math)
- 1. Naive In-Memory Hash Table: Storing 40 billion URLs raw (average 80 characters) requires 3.2 TB RAM for URL strings alone, excluding hash table pointer overhead.
- 2. Bloom Filter Bit Array Formula: For $n = 40\times 10^9$ keys and false positive probability $p = 0.001$ (0.1%), bits required $m = -\frac{n \ln p}{(\ln 2)^2} \approx 575 \times 10^9\text{ bits} \approx \mathbf{71.8\text{ GB RAM}}$.
- 3. Cluster Footprint: 72 GB RAM easily fits across a tiny 2-node Redis cluster with bitfield commands (`SETBIT` / `GETBIT`), reducing RAM requirements by 98%.
The Mercator Two-Tier URL Frontier: Prioritization & Politeness
A naive FIFO crawler either hammers a single web host to death or crawls low-value spam pages indefinitely. The production crawler separates prioritization from politeness into two distinct queue tiers.
Tier 1: Priority Queues (F1 ... Fk)
URLs are ranked by PageRank score, domain authority, and update frequency. High-priority news sites land in queue F1 (crawled every 15 minutes); static documentation lands in F10 (crawled monthly). A biased random selector picks URLs to avoid starvation.
Tier 2: Politeness Queues (B1 ... Bm)
Each politeness queue contains URLs from exactly one domain host (e.g. nytimes.com).
A heap-based Delay Table tracks the next permissible fetch timestamp for each queue:
worker_thread blocks if now() < next_fetch_time
Spider Traps & Infinite Frontier Exhaustion
How dynamically generated calendar pages, session tokens, and symlink loops paralyze distributed crawler fleets.
A misconfigured site generates endless recursive URLs: /catalog/item/1/similar/2/similar/3... or endless calendar pages /events?year=3024.
Because each generated URL has a unique query string or path parameter, Bloom filter deduplication marks them as new URLs.
The frontier fills with millions of junk links from a single domain. Worker threads spend 95% of their CPU parsing dynamic trap pages, starving the crawl of legitimate web content until queue disk buffers crash.
- URL Path Depth Hard Cap: Reject any URL with more than 10 slash segments or > 255 total characters.
- Per-Domain Page Budget Quotas: Cap non-whitelisted domains at a maximum of 10,000 crawled pages per month.
- Content SimHash Deduplication: Calculate a 64-bit fingerprint of page text. If fingerprint similarity > 95% across 20 pages from the same host, flag site as a template trap.
Six-Component Distributed Crawler Grid
The complete infrastructure decoupling URL scheduling, HTTP fetching, document parsing, and storage.
Simulate the Web Crawler Frontier Live
Test politeness delay timing, model Bloom filter false-positive rates, and observe frontier queue length dynamics under simulated spider trap loads.