Skip to content
SD-14 · Back to the write-up

Design a Web Crawler

A frontier with one queue per host feeds a fleet of polite async fetchers; parsers find links, and a Bloom filter and fingerprints keep URLs and pages from being fetched or stored twice.

Follow a request

Plan
Frontier
Fetch and parse
Web and storage
Recrawl schedulerDue URLs
URL database10B rows
URL frontierQueue per host
URL seen setBloom + store
DNS resolverCached
FetchersAsync, 45
ParsersLinks + SimHash
Websites100M hosts
Page storeWARC files
Page streamFetched pages
1fetcher → frontier · lease workA fetcher with free connections asks its frontier shard for ready URLs.1 / 8

The numbers, at a glance

For every 10 links we find……only 1 is a URL we have not seen
1 new URL9 already seen
Page storage grows fast125 TB of compressed pages a month
Copies are commonExact and near-duplicate pages
So pages are fingerprinted before they are stored or followed.

One fetch, in order

From leasing a URL to its links reaching the frontier. The host is not touched again until its delay has passed.

Frontier
Fetcher
DNS
Website
Page store
Page stream
Parser
Seen set
1 lease ready URLs
2 example.com/a, 60 s lease
3 resolve (cached)
4 93.184.216.34
5 GET /a
6 200, 80 KB
7 append WARC record
8 page + headers
9 done; host free at now + 1 s
10 page
11 30 links: seen?
12 3 new
13 3 new URLs
RequestResponseAsync, does not block

How the frontier hands out URLs

The decision this question is really about.

One FIFO queue
Gets us blocked
page on site A
40 links to site A
40 requests to A at once
+ Simple breadth-first crawl.− Long runs of the same host.
Priority table in SQL
Too slow
SELECT … ORDER BY priority
4,000 pops/s, row locks
+ Easy to inspect.− A query and update per URL.
Queue per host
Our pick
8 priority queues
One queue per hostHeap of next-allowed times
Only ready hosts are handed out
+ Fast and polite.− Custom code.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 50 pages/sMake it work
URL queue
CrawlerWebsites
SQL database
One process: FIFO queue, fetch, parse, store in SQL.
Stage 2 · ≈ 2,000 pages/sFetch politely
Frontier by host
Fetchers × 45DNS cacheWebsites
URL databasePage store
Queues per host, a fetcher fleet, DNS cache, pages in object storage.
Stage 3 · ≈ 4,000 pages/sSplit the work
Frontier by hostURL seen set
FetchersDNS cacheWebsites
Page streamParsers
URL databasePage store
Parsers behind a stream; a Bloom filter for seen URLs; fingerprints.
Stage 4 · 4,000 pages/s, 60% recrawlsStay fresh
Recrawl scheduler
Frontier by hostURL seen set
FetchersDNS cacheWebsites
Page streamParsers
URL databasePage store
Recrawl each URL by its change rate and importance.
Was this walkthrough useful?Your vote tells us what to improve next.