Chapter Twelve · Problem Six
Web Crawler
Three billion pages a month, fetched politely, across a 45-minute round.
"Design a crawler that downloads three billion web pages a month for a search index."
Every other problem in this book serves its clients. Here you are the client, on a web that owes you nothing and that you owe politeness. A server you have never met can be slow, can hand you pages without end, and can ask you to go away, and the one thing you may not do is knock it over. So the hardest rule in this design protects someone who is not your customer.
Four block chapters carry it. Chapter 3 gives you the partition key through Range, Hash and Directory, Picking the Partition Key and Hot Partitions, and here the key is the host. Chapter 6 gives you the link log from Queues, Logs and Pub-Sub, the link that arrives twice from Delivery Semantics at Scale, and from Backpressure and Load Shedding the arithmetic of a frontier, the list of URLs still to fetch, that outgrows its drain. Chapter 2's When the Cache Hurts brought the filter that says "definitely absent". And Chapter 5's Leases, Locks and Fencing opened on this very frontier, so its paused worker comes back here with the same tokens.
The problem sits between mid and senior. A mid-level candidate reaches partitioning by host. A senior one volunteers why a seen URL that is lost never comes back. Three problems do the damage: the frontier, which has to hold priority and per-host politeness together, meaning robots rules, one connection and a crawl delay; deduplication at three billion, with a seen-URL set that does not fit in memory and near-duplicate pages under different URLs; and the open web, with its infinite calendars, traps and slow servers.
Run the round for real before the first lesson: 45 minutes on a timer, your own crawler on paper, and a rule for what happens when many workers land on one small site. Scope stops at minute 10, First Design at 20 and Scaling It at 30, and Deep Dives and Curveballs runs the clock out at 45. If that small site has no answer in your drawing, you already know what to read for.