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
Score yourself
3 min read+10 XP
Score yourself
Give yourself 0, 1 or 2 points per row.
| Area | 0 points | 1 point | 2 points |
|---|---|---|---|
| Requirements | Started drawing | Pages and links | Politeness, freshness, duplicates and resilience agreed |
| Estimates | None | Numbers, not used later | Numbers that drove async fetching, object storage and a Bloom filter |
| API and data | Skipped | Some components | Frontier, fetcher and store interfaces; url_state and host_state |
| High-level design | Loop without details | Loop with boxes | Loop walked, with DNS, robots.txt, dedupe and re-crawl |
| Deep dive | Hand-waved | One topic | Frontier with per-host politeness, RFC robots rules, dedupe or host-based partitioning |
| Trade-offs | None named | Named when asked | Raised unprompted (Bloom false positives, split by host, trap limits) |
| Communication | Long silences | Mostly clear | Thought out loud, checked in, managed time |
12 to 14: strong hire signal. 8 to 11: solid, polish the weak rows. Under 8: redo the round in a week, timer on.
The bar: fresher vs SDE-2
| Fresher | SDE-2 | |
|---|---|---|
| Frontier | A queue of URLs (BFS) | Priority front queues, per-host back queues, next-allowed heap |
| Politeness | "Respect robots.txt" | RFC 9309 matching, caching rules, adaptive delays, back-off |
| Dedupe | A set of visited URLs | Normalisation, Bloom filter sizing, content hashes, near-duplicates |
| Scale | Many workers | Partition by host on a consistent-hash ring, forwarded links |
| Resilience | Not mentioned | Timeouts, size limits, traps, per-host breakers, re-crawl scheduling |
Common mistakes
- A single BFS queue, so hundreds of requests hit one site at once.
- Ignoring robots.txt, or parsing it with first-match rules.
- No URL normalisation, so the same page is fetched under dozens of URLs.
- Splitting work by URL, breaking per-host politeness.
- Storing pages in a database instead of object storage.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz