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
Fetch a page
Find new links
Recrawl a known page
A site asks us to slow down
A fetcher dies
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
The numbers, at a glance
1 new URL9 already seen
375 TBM3
750 TBM6
1.1 PBM9
1.5 PBM12
30% copies70% unique pages
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.
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.
SELECT … ORDER BY priority
4,000 pops/s, row locks
+ Easy to inspect.− A query and update per URL.
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.
URL queue
CrawlerWebsites
SQL database
Frontier by host
Fetchers × 45DNS cacheWebsites
URL databasePage store
Frontier by hostURL seen set
FetchersDNS cacheWebsites
Page streamParsers
URL databasePage store
Recrawl scheduler
Frontier by hostURL seen set
FetchersDNS cacheWebsites
Page streamParsers
URL databasePage store
Was this walkthrough useful?Your vote tells us what to improve next.