Design a Web Crawler
Design a crawler that downloads web pages for a search engine. It starts from a list of seed URLs, fetches each page, stores it, pulls out the links, and adds new ones to its to-do list. It must keep coming back to pages it already has, so the index stays fresh. Other teams read the stored pages to build the search index.
The target is 5 billion pages a month, about 1,930 pages a second, with room to run at 4,000 a second to catch up. That means billions of URLs to remember, 125 TB of compressed pages a month, and 100 million different websites, each of which expects us to be polite: one request at a time, honour robots.txt, and back off when asked. The hard parts are deciding what to fetch next without hammering any one site, never fetching the same URL or the same page twice, and not getting stuck in endless generated pages.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1What content?
- 2How many pages?
- 3How fresh?
- 4Must we obey robots.txt?
- 5How polite per site?
- 6Do we render JavaScript?
- 7How long do we keep pages?
- 8Where do URLs come from?
How to spend the 45 minutes
- 5minPart 1: Requirements: scale, politeness, freshness
- 5minPart 2: Estimates: pages/s, storage, URLs to remember
- 5minPart 3: API
- 15minPart 4: Architecture, stage by stage
- 15minPart 5: Deep dives: frontier, dedup, recrawl, traps