Design a web crawler
The setup
"Design a web crawler. Goal: crawl the entire indexable web (~50 billion pages). Goal latency: complete a full pass every 30 days. Politeness: don't hit any single site more than once per second."
Capacity estimation
Rate: 50B pages / (30 days × 86400 sec) = ~20K pages/sec Each fetch: avg ~500ms (varies wildly by site) Concurrent fetches needed: 20K × 0.5 = 10K parallel fetchers Storage per page: ~100KB compressed Total: 50B × 100KB = ~5 PB storage
The core loop
┌────────────────────┐
│ Frontier (URLs │ ← distributed priority queue
│ to crawl) │
└──────────┬─────────┘
│
↓ pick high-priority URLs (politeness-respecting)
┌────────────────────┐
│ Fetcher pool │ ← parallel HTTP fetches
└──────────┬─────────┘
│
↓ fetched HTML
┌────────────────────┐
│ Parser │ ← extract links, content, metadata
└──────────┬─────────┘
│
┌──┴──┐
↓ ↓
┌────────┐ ┌────────────────┐
│Storage │ │ Discovery: add │
│ │ │ new URLs to │
│ │ │ Frontier │
└────────┘ └────────────────┘
Design Decision 1: the Frontier — distributed priority queue
The frontier holds billions of URLs to crawl. Must be:
- Distributed (can't fit on one machine)
- Prioritised (high-value sites crawled more often than long-tail)
- Politeness-aware (don't hit same host too often)
- Resumable (worker crashes don't lose state)
Implementation: per-priority queues stored in distributed system (Kafka, custom). Each URL has metadata: priority score, host, last-crawled-at.
| Priority tier | Examples | Re-crawl frequency |
|---|---|---|
| P0 — Critical | Wikipedia, news sites, social | Hourly |
| P1 — High | Mid-popularity sites, blogs | Daily |
| P2 — Standard | Long-tail | Monthly |
| P3 — Low | Rarely linked-to | Quarterly |
PageRank-style signals determine priority: a URL is more important if it has many incoming links from high-priority sites. Feedback loop: crawled content → analyze links → update URL priorities.
Design Decision 2: politeness — per-host rate limiting
Design Decision 3: deduplication
Cross-examination round 1: scale of the frontier
Takeaway
Web crawlers are a fascinating exercise in scale and politeness. The hardest parts are not technical primitives but operational: politeness contracts with hosts, content deduplication at petabyte scale, and prioritising the right URLs with finite resources. The deeper insight: at large scale, the priority of what to crawl matters more than the throughput of crawling. Google's original PageRank insight was that you can use the crawl graph itself to decide what's worth crawling more often. That feedback loop — crawl shapes priorities shapes crawl — is what distinguishes great crawlers.