Infrastructure primitives
Web crawler - a frontier, and the trap of crawling forever
fetch politely, dedup honestly, never loop
What this board gets wrong on purpose
The tension
The seen set is a Bloom filter, so it is wrong in exactly one direction: a false positive says a page has already been crawled when it has not, the page is dropped, and NOTHING LOGS IT - at one percent over five billion URLs that is fifty million pages silently missing from the corpus and no alert that could fire. Politeness pulls the other way: one request per host per second is correct behaviour and it means a site with ten million pages takes a hundred and fifteen days, so the freshness target and the politeness rule cannot both be met and neither is negotiable. And the trap detector is pure heuristic - depth caps and pattern matching - so a faceted listing with a hundred million URL permutations still burns real crawl budget before anybody notices.
Requirements
Ask these before drawing anything
- How many pages, and how fresh? A billion pages refreshed monthly and a hundred million refreshed hourly are different systems, not the same system with a different number in it.
- Whose web is it - the open web, one customer site, or a set of known domains? A crawl of known domains can negotiate rate limits and skip almost everything on this board.
- Is JavaScript rendering required? A headless browser is roughly fifty times the CPU of an HTTP fetch, and that single answer moves the fleet from twenty machines to a thousand.
- What counts as a duplicate: the same URL, the same bytes, or the same article on two domains? Each needs a different mechanism and they are often all three.
- What is the politeness policy, and who owns the relationship when a site complains? There will be complaints.
- Is the crawl allowed to be stopped and restarted, or must it be continuous? That decides whether the frontier has to be durable.
- What happens to content that disappears - is a 404 a deletion from the corpus or an outage to retry?
Functional
- Crawl one billion pages and revisit each within thirty days.
- Obey robots.txt, including crawl-delay, and cache it per host.
- Never fetch the same URL twice within a refresh cycle, and never store the same content twice regardless of how many URLs served it.
- Discover new URLs from fetched pages and feed them back into the frontier.
- Prioritise: a news homepage is worth more, more often, than a ten-year-old forum thread.
- Survive a restart without losing the frontier or the seen set.
Non-functional
- Politeness is a hard constraint, not a target: at most one in-flight request per host, and honour crawl-delay when it is longer than the default one second.
- Throughput of 400 pages a second sustained, 800 at peak.
- The crawler may be down for an hour without anybody caring. It is a batch system - it degrades by crawling more slowly, which is a completely different availability story from anything serving user requests.
- The frontier and the seen set are the only components whose loss is expensive, and they must be durable.
- Identify honestly in the User-Agent, with a URL explaining the crawler and a contact address.
Out of scope
- Ranking and the index itself. This system fills a queue; somebody else reads it.
- Paywalled or authenticated content.
- Rendering JavaScript, in version one. The number is in the capacity page so that the decision is costed rather than assumed.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, an 8-step narrated walkthrough and a 4-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
- 4tables30 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan
More boards
The building blocks an interview asks you to build from scratch.