Design a Distributed Web Crawler
Crawl the World Wide Web: URL Frontier, Politeness policies (robots.txt, domain delay), Duplicate detection (Bloom Filters & SimHash), and distributed workers.
Distributed Web Crawler Architecture & URL Frontier ๐ท๏ธ
URL Frontier with dual Priority and Politeness scheduling queues, Bloom filter URL deduplication, and SimHash content fingerprinter.
01.1. Functional & Non-Functional Requirements
A distributed web crawler systematically navigates the World Wide Web to download, index, and archive billions of web pages for search engines, price monitors, or AI model datasets.
Functional Requirements
- Scalable Web Crawling: Ingest seed URLs and recursively discover, fetch, and parse billions of hyperlinks.
- Politeness & robots.txt Compliance: Strictly respect
robots.txtexclusion standards, crawl delays, and never overwhelm any individual domain with rapid-fire requests. - URL & Content Deduplication: Detect and discard duplicate URLs and near-duplicate HTML content (e.g., identical content with different tracking parameters).
- JavaScript SPA Rendering: Support headless browser rendering (Puppeteer/Playwright) for dynamic single-page applications.
Non-Functional Requirements
- Massive Scalability: Crawl
1 billionweb pages per month (~ 400 pages/sec). - Extensibility & Modularity: Modular architecture to support adding new protocols (FTP, sitemaps) and media parsers (PDF, image indexing).
- Spider Trap Resilience: Detect and terminate infinite looping URL traps (e.g., dynamic calendar links:
/calendar?month=12&year=2099).
02.2. Capacity & Scale Estimation
Crawling Scale
- Monthly Crawl Target:
1 billionweb pages. - Crawling Throughput:
Pages per second = \frac{1,000,000,000}{30 ร 86,400} โ 386 pages/sec (Peak: 1,000 pages/sec)
Storage & Bandwidth Estimation
- Average HTML Page Size:
100 KB(after gzip compression:~ 30 KB). - Monthly Storage Footprint:
1B pages ร 30 KB = 30 Terabytes (TB)/month \implies 360 TB/year
- Ingress Network Bandwidth:
Peak Bandwidth = 1,000 pages/sec ร 100 KB = 100 MB/sec = 800 Mbps (Megabits/sec)
03.3. The URL Frontier: Priority and Politeness Scheduling
The URL Frontier is the brain of the crawler. It stores unvisited URLs and schedules when and where each URL is dispatched.
The Two-Tier Queue Design (Mercator Model):
-
Priority Queues (Importance / Quality Filter):
- URLs are scored based on PageRank, domain authority, and update frequency.
- High-priority pages (Wikipedia, major news outlets) are placed into top priority queues (
F_1, F_2) to be crawled first; low-authority blogs enter lower queues (F_k). - A Prioritizer Worker pulls probabilistically from higher queues.
-
Politeness Queues (Domain Rate-Limiting):
- An aggressive crawler must never trigger Denial of Service (DoS) on a website.
- The Queue Selector routes URLs from priority queues into dedicated per-domain Politeness Queues (
B_1, B_2, \dots, B_m). - Rule: A worker thread assigned to domain
example.comfetches one page, downloads the content, and enforces a politeness delay (e.g.,1,000 ms) before pulling the next URL forexample.com.
04.4. Deduplication: Bloom Filters and SimHash
Over 30\% of the internet consists of duplicate or near-duplicate web pages. Crawling duplicates wastes petabytes of storage and network bandwidth.
1. URL Deduplication: In-Memory Bloom Filter
- Storing 10 billion URL strings in RAM requires hundreds of gigabytes.
- A Bloom Filter provides an
O(1)space-efficient probabilistic set representation:- If Bloom Filter returns False: The URL has definitely never been seen
\impliesProceed to crawl! - If Bloom Filter returns True: The URL is likely already crawled
\impliesCheck persistent DB or discard. - With 10 hash functions and 10 bits per entry, a 1-billion-URL Bloom filter consumes only
~ 1.2 GBof RAM with a false positive rate< 1\%.
- If Bloom Filter returns False: The URL has definitely never been seen
2. Content Deduplication: SimHash (Near-Duplicate Fingerprinting)
Web pages often contain identical content with minor variations (e.g., copyright year changed from 2025 to 2026, or different dynamic session IDs).
- SimHash Algorithm:
- Tokenize HTML body into word tokens and assign weights.
- Compute 64-bit cryptographic hashes for each token.
- Combine weighted hash bits into a single 64-bit SimHash fingerprint.
- Compare new page fingerprints using Hamming Distance (number of differing bits).
- If
Hamming Distance โค 3, pages are flagged as near-duplicates and dropped from indexing.
05.5. Crawling Workflow & Worker Pipeline
End-to-End Crawl Cycle:
- Dequeue URL: Worker pulls polite URL from the frontier.
- DNS Resolution & robots.txt Check:
- Lookup domain IP from local in-memory DNS cache to avoid exhausting public DNS servers.
- Fetch and cache
robots.txtrules for the host.
- HTTP Fetch: Download HTML over HTTP/2 with gzip compression and timeouts (
< 5s). - Content Fingerprint: Calculate SimHash; if already seen, discard.
- Store Document: Save raw HTML in S3 (WARC format) and metadata in Cassandra/HBase.
- Link Extraction & Normalization: Extract
<a href="...">tags, convert relative paths to canonical absolute URLs, and feed through the Bloom Filter before enqueuing back to the URL Frontier.
06.6. Spider Traps, Fault Tolerance & Performance Bottlenecks
Avoiding Spider Traps
Spider traps are infinite dynamic loops (e.g., dynamic calendar pages, nested directory structures: /dir/dir/dir/...).
- Mitigations:
- Maximum Crawl Depth: Cap recursion depth (e.g., max 15 hops from seed).
- URL Length Limit: Drop URLs exceeding 255 characters.
- Per-Domain Page Limit: Cap total crawled pages per domain to 100,000 pages per cycle.
Fault Tolerance & State Checkpointing
- Workers are stateless and report heartbeats. If a worker crashes mid-download, the URL is re-queued.
- URL Frontier queue states are snapshotted to distributed disk (RocksDB/Kafka) every 10 minutes to resume immediately after cluster reboots.
โ๏ธArchitectural Trade-offs & Production Realities
Architectural Advantages
- Dual-tier URL Frontier guarantees strict domain politeness while prioritizing high-value pages
- Bloom filters and SimHash eliminate 90%+ of redundant URL fetches and near-duplicate storage bloat
- Stateless worker architecture allows horizontal auto-scaling to thousands of nodes
Trade-offs & Constraints
- Headless browser rendering for JavaScript SPAs consumes 10x more CPU and memory per worker
- Dynamic spider traps require continuous heuristic tuning to prevent crawler resource drain
Googlebot and Common Crawl crawl billions of daily web pages using distributed DNS resolvers, headless Chrome rendering clusters, and petabyte-scale distributed URL frontiers running on Kubernetes and BigTable.
๐ฏ Staff+ Engineering Takeaways
- The URL Frontier enforces politeness (per-domain delay) and PageRank priority.
- Bloom filters enable in-memory URL deduplication with minimal RAM usage.
- SimHash 64-bit fingerprints detect near-duplicate HTML documents across different URLs.
- Cache DNS lookups and robots.txt files aggressively to eliminate network bottlenecks.
Topic Knowledge Assessment ๐ง
Step through 2 scenario questions to test your staff-level grasp.
What is the purpose of the Politeness Policy in a distributed web crawler's URL Frontier?
How clear and staff-actionable was this system breakdown?