SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 14
Design a web crawler
A search team needs fresh copies of public web pages to build an index. Starting from a seed list, the crawler fetches pages, follows links to find more, and comes back later to pick up changes, without ever hammering a website or ignoring its crawling rules.
Requirements
- Starting from seed URLs, fetch HTML pages, extract links, and discover new URLs.
- Obey robots.txt and never send more than one request per second to a host unless its robots.txt allows more.
- Store each fetched page with its URL, fetch time, and HTTP metadata for the indexing team.
- Recrawl known pages on a schedule that reflects how often they change.
Constraints and assumptions
- Target 1 billion page fetches a month, with peaks around 1,000 fetches per second.
- Average page 100 KB of HTML; about 10 million distinct hosts; 1 million seed URLs.
- Roughly 30% of fetched pages are exact or near duplicates of pages already stored.
- Some pages (news front pages) change hourly; most change less than once a month.
- Each discovered page links to about 50 URLs, most already known.
Out of scope for the first sketch
Rendering JavaScript-heavy pages · Building the search index and ranking · Images, video and other non-HTML content
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design a web crawler
Finish your first sketch before answering these. Cross out freely.
- robots.txt for a host times out or returns a 5xx error. Do you crawl that host? What do you cache, and for how long?
- How do you keep any host at one request per second while still keeping 1,000 fetches per second flowing overall?
- The same article shows up under 40 URLs (tracking parameters, mirrors, print views). How do you avoid fetching and storing all of them?
- You have a fixed fetch budget. How do you decide when each known URL is due for a recrawl?
- A fetcher machine crashes while holding thousands of leased URLs. What happens to them, and could any host get hit twice as hard?
Compare afterwards: worked approaches and reading at sketchbook /questions/web-crawler/review