Build a Large-Scale Web Crawler Architecture
System DesignModel answerLast updated
Design a distributed crawler that fetches and processes billions of web pages weekly while respecting rate limits and avoiding duplicate work.
Problem
You need to architect a web crawling platform that continuously discovers and downloads pages from the public internet. The system must handle billions of URLs, keeping content reasonably current without overwhelming servers or wasting resources on redundant downloads.
What the system must do
- Find new URLs: Extract links from crawled pages to discover more content
- Download respectfully: Fetch pages while honoring robots.txt directives and avoiding request floods to any single server
- Avoid redundancy: Skip URLs and content you've already processed
- Prepare for search: Output cleaned documents ready for a search indexing pipeline
Scale targets
- Corpus size: 10 billion pages
- Refresh cycle: Complete recrawl within one week
- Throughput: Sustain roughly 15,000-20,000 pages per second on average
- Freshness: Prioritize frequently-changing content over static pages
What to provide
- Architecture overview: Describe the major components and how data flows between them
- Storage approach: Explain how you track which URLs have been seen and manage the crawl queue at this scale
- Capacity estimates: Calculate storage needs and server counts to meet throughput goals
- Design decisions: Discuss trade-offs between complexity, cost, and how current the data stays
Hints
Hint 1
Start by calculating the required pages-per-second rate and estimating typical page sizes to understand bandwidth and storage needs
Hint 2
The URL queue needs two separate concerns: choosing what to crawl next (priority) versus respecting per-host rate limits (politeness)
Hint 3
Use probabilistic data structures like Bloom filters for fast duplicate detection, backed by authoritative storage for accuracy
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
Approach
A strong answer demonstrates capacity-driven design: derive concrete numbers first, then let those numbers shape the architecture. The core challenge is balancing three competing goals: comprehensive coverage, data freshness, and respectful crawling behavior.
Step 1: Scope and Assumptions
Clarify these points upfront:
- Content types: Focus on HTML pages initially; JavaScript rendering and multimedia can be follow-up topics
- Access rules: Honor robots.txt and crawl only public web content
- Downstream boundary: Output clean documents (text, links, metadata) for another system to index; building the actual search index is separate
- Refresh strategy: Most pages refreshed weekly, but dynamic pages more often and static pages less often
Step 2: Capacity Calculations
Throughput requirements:
- 10 billion pages / (7 days × 86,400 sec/day) ≈ 16,500 pages/second average
- Design for 30,000 pages/second peak to handle load spikes
Storage and bandwidth:
- Average page: ~100 KB raw HTML, ~25 KB after compression
- Inbound bandwidth: 16,500 × 100 KB ≈ 1.65 GB/s (≈13 Gbps)
- Content storage: 10B × 25 KB ≈ 250 TB compressed. With replication and keeping recent versions, budget ~2 PB
- URL metadata: Track ~50 billion URLs (discovered exceeds crawled). At ~200 bytes per URL (location, hash, last crawl timestamp, change frequency, priority), that's ~10 TB in key-value stores
Server estimates:
- Fetchers: Each page takes ~1 second end-to-end (DNS, connection, download). To sustain 30k pages/s, need ~30k concurrent operations. A single async I/O server can handle ~300-500 pages/s, requiring ~100 fetcher machines
- Parsers: Link extraction and text processing takes ~5-10ms CPU per page. At 30k pages/s, need ~300 cores or ~15-20 parser nodes
- URL management: ~20-30 shards for the frontier queue
- Storage cluster: ~100+ nodes for the content repository
Step 3: Architecture
The system consists of these major components:
URL Frontier (sharded by host)
- Maintains the queue of URLs to crawl
- Sharded using consistent hashing on hostname
- Manages priority (what to crawl) and politeness (when to crawl from each host)
Fetcher Pool
- Asynchronous workers that execute HTTP requests
- Cache DNS lookups and robots.txt files
- Use conditional requests (If-Modified-Since headers) for recrawls
- Respect Crawl-Delay directives
Content Repository
- Object store or distributed filesystem holding raw page content
- Compressed storage with replication for durability
Parser and Filter Pipeline
- Extracts text, links, and metadata
- Performs content deduplication and quality scoring
- Outputs cleaned documents for the indexer
Data flow:
- Frontier selects a URL and assigns it to a fetcher
- Fetcher downloads the page (after checking robots.txt cache)
- Raw content is stored and an event published to a message queue
- Parser processes the page, extracts links, and performs deduplication
- Extracted links flow back to URL filters (via Kafka, partitioned by host)
- New URLs pass through Bloom filter → key-value lookup → frontier insertion
Step 4: URL Frontier Design
Use a two-level queue structure:
Priority tier (front queues):
- Multiple priority levels (e.g., 5-10 queues from critical to low)
- Priority score based on: estimated PageRank, change frequency, and time since last crawl
- Selector pulls from queues with bias toward higher priority
Politeness tier (back queues):
- One queue per host domain
- Min-heap ordered by "next allowed fetch time" for each host
- Worker takes one URL from the top host, then reinserts that host with delay = max(Crawl-Delay, 10× last response time, exponential backoff on errors)
- Rate limiting happens locally per shard since each host maps to exactly one shard
Persistence: Keep active queue heads in memory, spill tails to disk (RocksDB). Regular checkpointing enables recovery.
Step 5: Deduplication Strategy
URL-level dedup:
- Normalize: lowercase host, remove fragments, sort query parameters, strip tracking tokens
- Compute 64-bit fingerprint
- Check shard-local Bloom filter (~60 GB total across all shards for 50B URLs at 1% false positive rate)
- On "maybe present" result, confirm with authoritative key-value lookup
- Bloom filters need periodic rebuilding or use counting/cuckoo variants
Content-level dedup:
- Exact duplicates: SHA-256 hash of normalized body text
- Near-duplicates: 64-bit SimHash with Hamming distance ≤ 3 threshold
- For SimHash lookup, use block permutation indexing to efficiently find similar fingerprints
- Mark duplicates as aliases to canonical URLs; don't re-index
Step 6: Freshness Model
Not all pages need the same refresh rate. Model each page's change behavior:
- Estimate change frequency λ from historical content hash diffs
- Set revisit interval ≈ 1/λ, clamped between 1 hour and 30 days
- Weight by importance (high-value sites checked more often)
- News sites might refresh hourly, archives monthly, averaging to the weekly target
Optimization signals:
- HTTP 304 responses (unchanged) cost minimal bandwidth
- Sitemap lastmod timestamps
- RSS/Atom feeds for rapid change detection
Step 7: Key Trade-offs
Completeness vs. Freshness
- More frequent recrawls keep data current but reduce coverage breadth
- Solution: Adaptive scheduling based on observed change rates
Politeness vs. Throughput
- Aggressive crawling can overwhelm small hosts
- Solution: Per-host rate limiting with exponential backoff; mega-sites get higher allowances but still controlled
Dedup Accuracy vs. Speed
- Bloom filters are fast but have false positives
- Solution: Two-tier check (Bloom → authoritative store) balances speed and correctness
Centralization vs. Scalability
- Centralized frontier is simpler but becomes a bottleneck
- Solution: Shard by host, accepting that global priority is approximate
Common Mistakes
- Ignoring politeness: A design that doesn't enforce per-host rate limits will get IP-banned
- No URL normalization: Treating example.com/?b=2&a=1 and example.com/?a=1&b=2 as different wastes resources
- Single dedup mechanism: URL dedup and content dedup solve different problems and need different approaches
- Static priority: All pages treated equally leads to stale high-value content and wasted bandwidth on low-value pages
- Missing capacity math: Hand-waving about "we'll add more servers" without calculating actual throughput needs
Complexity Analysis
- URL frontier operations: O(log H) per URL where H = number of active hosts (heap operations)
- Bloom filter check: O(k) where k = number of hash functions (~10), effectively O(1)
- SimHash similarity search: O(N/16) with 4-way partitioning, where N = corpus size