A crawler is a loop: take a URL, fetch it, extract its links, repeat. At a billion pages the hard parts are staying polite to every website, never fetching the same thing twice, and surviving the strange corners of the web.
Requirements. Start from seed URLs, follow links, store pages for indexing, recrawl pages as they change and obey robots.txt; never overload a website, scale to hundreds of fetchers, and survive broken HTML, slow servers and crawler traps.
Fetch rate
385 pages per second1B pages a month, peak about 800
Storage
500 TB a month1B pages × 500 KB
URLs seen
about 12 GB10B URLs in a Bloom filter at 1%
The design. A URL frontier decides what to fetch and when: front queues order URLs by priority, and a router keeps one back queue per host, so a fetcher takes a host’s next URL only after its politeness delay. Fetchers download, parsers extract links, and every link is normalized and checked against a Bloom filter of URLs already seen. Content is checked too: a checksum catches exact copies and SimHash catches near duplicates. Depth limits and per host budgets stop crawler traps.
Interview prompt
Design a web crawler that collects a billion pages a month for a search engine.
Requirements and estimates
Functional requirements
Start from seed URLs and follow links.
Store page content for indexing.
Recrawl pages according to how often they change.
Obey robots.txt.
Non-functional requirements
Politeness: never overload any single website.
Scales to hundreds of fetcher machines.
Robust to broken HTML, slow servers and crawler traps.
Extensible to new content types such as PDFs.
Estimates
Fetch rate 1B pages ÷ 2.6M s per month ≈ 385 pages/s, peak ≈ 800
Storage 1B × 500 KB = 500 TB per month, ≈ 30 PB in 5 years
URL seen 10B URLs in a Bloom filter at 1% ≈ 12 GB of memory
Whiteboard
What you sketch in the first five minutes: the loop itself, then the queues that keep it polite.
1. The loop
Say: a crawler is a loop; the design is everything that keeps it polite and finite.
Take a URL from the frontier and fetch the page.
Store it, extract its links and normalize them.
Drop the links a Bloom filter has seen, and queue the rest.
Next question: DNS turns out to be the bottleneck. Cache lookups per host on each fetcher.
2. One queue per host
Say: front queues decide what matters, back queues decide when.
The prioritizer puts important, often changing pages first.
A router keeps one back queue per host.
A heap of next allowed times says which host may be fetched again.
Next question: one slow server ties up a fetcher. Tight timeouts, and its own back queue keeps the delay to that host.
The URL frontier
Front queues decide what matters, back queues decide when. The prioritizer ranks URLs by importance and how often the page changes. The router keeps one back queue per host, and a fetcher may take that host’s next URL only after its politeness delay has passed, tracked in a heap of next allowed times.
Never twice
Same URL
Normalize first: lowercase the host, drop fragments, sort query parameters, strip tracking parameters. Then check a Bloom filter of URLs already seen. A false positive means a page is occasionally skipped, which is acceptable; it never causes a duplicate fetch.
Same content
Mirrors and session parameters serve identical pages under many URLs. A checksum of the content catches exact copies; SimHash catches near duplicates, such as the same article with a different ad block.
Trap
What happens
Defense
Endless calendars
“Next month” links forever
Maximum depth and pages per host
Session IDs in URLs
Every visit looks like a new page
Strip known parameters, content dedupe
Generated link farms
Pages that link to ever new pages
URL length limits, per host budgets
Slow servers
Fetchers sit idle waiting
Tight timeouts; one host per back queue isolates it
What the interviewer probes next
How do you decide when to recrawl a page?
Estimate each page’s change rate from past crawls: news front pages hourly, documentation monthly. Use conditional requests with If-Modified-Since or ETag, so unchanged pages return a 304 with no body.
What about pages built with JavaScript?
Send them to a separate render queue served by headless browsers. Rendering costs far more than fetching, so do it only when the static HTML lacks the content.
How are hosts split across crawler machines?
Hash the hostname to a machine with consistent hashing. One machine then owns all politeness state for a host, and adding machines moves only some hosts.
DNS turns out to be the bottleneck. Why, and what helps?
Each lookup can take tens to hundreds of milliseconds and many resolvers are single threaded. Run a caching resolver on every crawler machine and respect record TTLs.