StackMonkey
Home / Templates / Web Crawler

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.

Monthly Crawl Volume
1 Billion pages
33.3M pages / day
Crawl Throughput
400 pages/sec
1,200 peak burst rate
Deduplication Accuracy
99.99%
Scalable Bloom filter
Politeness Governor
โ‰ฅ 1.0s / host
Zero target DoS risk
Step 1 of 4

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%.
Step 2 of 4

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:

next_fetch_time = last_fetch_time + max(robots_txt_delay, 1000ms)
worker_thread blocks if now() < next_fetch_time
Step 3 of 4

Spider Traps & Infinite Frontier Exhaustion

How dynamically generated calendar pages, session tokens, and symlink loops paralyze distributed crawler fleets.

The Spider Trap Black Hole

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.

Production Trap Defenses
  • 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.
Step 4 of 4

Six-Component Distributed Crawler Grid

The complete infrastructure decoupling URL scheduling, HTTP fetching, document parsing, and storage.

01 ยท Dedicated DNS Cache Tier
CoreDNS / Unbound Cluster
Standard DNS calls take 50ms - 200ms. A local in-memory DNS caching tier resolves hostnames in sub-0.5ms with aggressive TTL overrides.
02 ยท Mercator URL Frontier
Kafka + RocksDB Priority Queues
Maintains priority queues and host politeness delay tables. Emits batches of fetch tasks strictly respecting robots.txt crawl delays.
03 ยท Async Fetcher Fleet
Go / Rust High-Concurrency Pods
Executes non-blocking HTTP GET requests with custom User-Agent headers, 5s timeout limits, and automatic gzip/brotli decompression.
04 ยท Scalable Bloom Filter Store
Redis Cluster Bitfield Arrays
Evaluates URL uniqueness in sub-1ms. Discards 98% of discovered duplicate hyperlinks before they ever enter the frontier queue.
05 ยท Parser & Link Extractor
HTML Tokenizer Microservices
Parses DOM trees, extracts canonical `<a href>` links, strips session query parameters, and normalizes relative URLs to absolute links.
06 ยท Raw Document Blob Storage
Amazon S3 / Google Cloud Storage
Appends crawled text into compressed WARC (Web ARChive) or Parquet format partitioned by crawl timestamp and domain hash for batch ML training.
Interactive Discrete Event Simulation

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.