Design a Web Crawler at Scale
1. Problem Statement & Scope Clarification
System Mission
Design a distributed, fault-tolerant, planetary-scale web crawler (similar to Googlebot, Bingbot, and Common Crawl) capable of crawling 1 Billion web pages per month, respecting domain politeness and robots.txt specifications, eliminating duplicate URLs and near-duplicate content, and persisting raw web snapshots into Amazon S3 for downstream search indexing and LLM training pipelines.
Functional Requirements
- Scalable Distributed Crawling: Crawl billions of web pages starting from a curated set of seed URLs, traversing outbound hyperlinks up to a bounded depth.
- Politeness &
robots.txtCompliance: Respect domain crawl-delays, disallow directives, and cap request rates to a maximum of 1 request per second per target host. - URL & Content Deduplication:
- URL Deduplication: Avoid re-fetching visited URLs within a 30-day freshness window.
- Near-Duplicate Content Detection: Detect identical or template-modified mirror pages using 64-bit SimHash fingerprints.
- HTML Parsing & Link Extraction: Extract canonical URLs, page titles, text content, and outbound links, normalizing relative paths to absolute URI standards.
- Durable Web Archive Storage: Persist raw HTML and WARC (Web ARChive) formatted files into Amazon S3 Standard-IA.
Non-Functional Requirements (SLAs & SLOs)
- Scale: 1 Billion pages/month ( sustained, Peak: ).
- Fault-Tolerance: 100% resilient to worker container termination via AWS EC2 Spot Instances ( compute cost reduction).
- Extensibility: Modular architecture supporting pluggable media downloaders and headless browser rendering (Playwright) for JavaScript-heavy single-page applications.
2. Capacity & Scale Estimation (Back-of-the-Envelope Math)
Ingestion & Throughput Derivations
- Monthly Target: (1 Billion pages/month).
- Average Crawl Rate:
- Peak Crawl Rate ( multiplier):
- Average Page Payload: (HTML + metadata).
- Peak Ingress Network Bandwidth:
Storage Footprint (Annual Accumulation)
- Monthly Raw Storage:
- Annual Storage Footprint (Compressed Zstandard):
Memory Sizing for URL Deduplication (Bloom Filter)
- Tracking 5 Billion discovered URLs with a false positive rate (): A modest Amazon ElastiCache Redis Cluster easily hosts this Bloom filter in memory.
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing vector architecture diagram...
4. URL Frontier Architecture (The Mercator Model)
To solve the dual challenges of Priority (crawling high-quality pages first) and Politeness (never overloading a single target web server), the crawler implements the Mercator Two-Tier Queue System:
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Politeness Heap Algorithm
- Each host queue maintains a state record:
(hostname, last_access_timestamp, crawl_delay_ms). - When a worker requests a URL, the coordinator inspects the Min-Heap.
- If , the worker pops the next URL for that host, fetches the page, and reschedules the host in the heap for (minimum 1,000ms).
- This mathematically guarantees that no single web server ever receives concurrent or rapid-fire hits.
5. Storage Engine & Near-Duplicate SimHash Algorithms
1. 64-Bit SimHash Near-Duplicate Detection Algorithm
To prevent storing millions of mirror pages or template variations:
- Tokenize HTML body text into word shingles (e.g. 3-word n-grams).
- Compute 64-bit cryptographic hash for each shingle.
- Initialize a 64-element weight vector .
- For each shingle hash, add to if bit , else .
- Form the final 64-bit fingerprint: bit if , else .
- Hamming Distance Match: If , the pages are near-duplicates; the crawler drops the redundant payload and only records canonical metadata.
2. DynamoDB Crawl State Schema (CrawlStateTable)
PK (Partition Key) | SK (Sort Key) | Attributes | Description |
|---|---|---|---|
HOST#<hostname> | ROBOTS | disallow_rules (LIST), crawl_delay_ms (NUM), cached_at (TTL 24h) | Cached robots.txt policies |
URL#<sha256(url)> | METADATA | url_raw, simhash_64, http_status, s3_uri, crawled_at | Visited URL audit record |
Unlock Complete Architecture & Production Runbooks
You have explored the free architectural preview (~48%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.