36. Design a Web Crawler
1
The interview prompt2
36.1 What do you ask first?3
36.2 How big is this, really?4
36.3 What are the doors?5
36.4 What do we store?6
36.5 What does the whole system look like?7
36.6 How does the URL frontier work?8
36.7 How do politeness and robots.txt work?9
36.8 How do you de-duplicate with Bloom filters?10
36.9 How do you crawl with many machines?11
36.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab36. Design a Web Crawler
36.5 What does the whole system look like?
3 min read+10 XP
Step 4: High-level design (10 minutes)
Figure: the final design is one loop, frontier → fetch → parse → filter → frontier, run on many nodes.
The crawl loop, step by step:
- The frontier hands out the next URL whose host is allowed to be fetched now (36.6).
- A fetcher checks the host's cached robots.txt (36.7), resolves the host through a DNS cache, and downloads the page with a timeout and a size limit.
- The page is parsed; its normalised text is hashed, and if the content was already seen, it's recorded as a duplicate and not stored again (36.8).
- New pages go to object storage, and an event tells the indexer (Chapter 19).
- The link extractor pulls out links, normalises them, drops ones that are filtered (wrong type, blocked domain, too deep, too long), and checks the seen-URL filter. New URLs go into the frontier with a priority.
- A re-crawl scheduler puts known URLs back into the frontier when they're due, more often for pages that change often.
Interviewer pushback:
- "What about spider traps, like a calendar with infinite 'next month' links?" → Limit URL length and path depth per site, cap pages per host per crawl, detect repeating path patterns, and lower priority for URLs that keep producing near-identical pages.
- "A site is slow or returning errors." → Back off that host: longer delays, fewer concurrent connections, and pause it after repeated failures (Chapter 29's circuit breaker, per host).
Memory code: "Frontier, fetch, parse, filter, back to the frontier."
Offer: "The interesting parts are the frontier, politeness and robots.txt, de-duplication, and splitting the crawl across machines. Which would you like?"