Design a Scalable Web Crawler: URL Frontier, Politeness, Bloom Filters & Deduplication
Crawling Billions of Pages Without Breaking the Web
Distributed Web Crawler Architecture
1. End-to-End Crawling Pipeline
[Seed URLs] ──► [URL Frontier] ──► [HTML Downloader] ──► [Content Parser]
▲ (DNS Cache + │
│ robots.txt) ▼
[URL Seen? / Filter] ◄── [URL Extractor] ◄── [Content Seen? (SimHash)]
- Seed URLs: High-authority entry points partitioned across regions/topics.
- URL Frontier: Two-stage queue system balancing priority and politeness.
- HTML Downloader: Fetches pages asynchronously (
asyncio/epoll), honoringrobots.txtrules cached locally per host. - Content Parser & Dedup: Strips invalid markup and fingerprints text to avoid indexing duplicate mirrors (~29% of web pages are duplicates!).
2. Deep Dive: The Two-Stage URL Frontier
┌──► Priority Queues (High / Med / Low PageRank)
URLs ────┤ │
│ ▼ (Router maps host -> single worker queue)
└──► Back Politeness Queues:
├── Queue 1: wikipedia.org (1 req / 2 sec)
├── Queue 2: python.org (1 req / 2 sec)
└── Queue 3: arxiv.org (1 req / 5 sec)
- Front Queues (Priority): Rank URLs by authority, update frequency, or traffic.
- Back Queues (Politeness): Each worker thread reads from a dedicated FIFO queue bound to one hostname (via a hash table
host -> queue), enforcing a delay (last_fetch + delay) between requests to that domain.
3. High-Performance Optimizations
- Local DNS Resolver: Standard synchronous OS DNS lookups block threads for 10–100ms. Run a dedicated local caching DNS service (
Unbound/ in-memory map) refreshed asynchronously. - Content Deduplication (
SimHash/ Locality-Sensitive Hashing): Cryptographic hashes catch byte-identical pages; SimHash catches near-duplicates (e.g., identical pages differing only by a session timestamp). - URL Seen (
Bloom Filter+ Disk KV): Store billions of visited normalized URLs compactly in a Bloom filter (false positives skip an extra crawl slightly; zero false negatives) backed by RocksDB. - Spider Trap & Endless Loop Defense: Cap maximum URL path depth/length (e.g., reject infinite calendar URLs like
/cal/2026/12/01/next/next/...) and maintain a domain blocklist.