Infrastructure primitives
Web crawler - a frontier, and the trap of crawling forever
Why a crawler that feeds on its own output needs politeness, deduplication and loop brakes more than speed.
The first act plays here. Owned once with credits, never a subscription.
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.
Practise this as an interview
Take Web crawler - a frontier, and the trap of crawling forever as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
A crawler is the classic interview system whose output is its own input: every page fetched produces more work, so the hard parts are brakes rather than speed. It probes whether you can make politeness a structural property of the queue, deduplicate at two different levels, and size a probabilistic structure while saying out loud what it gets wrong. Search engines, web archives, price monitors and training-data pipelines all run this loop, and the ones that get it wrong are blocked at the edge or drown in crawler traps.
What you will learn
- Why the frontier is per-host queues under a priority selector, and why one request per host per second makes a 10-million-page site take 115 days against a 30-day refresh.
- Sizing: a billion pages a month is 386 fetches/s on average and 772 at peak, about 4,000 sockets across 20 IO-bound fetchers, with parsing on a separate CPU-bound fleet.
- URL dedup against content dedup: normalise every link before comparing it, then SHA-256 the stripped body so twelve URLs store one page.
- The Bloom filter trade: 9 GB in RAM instead of a 230 GB exact set, paid for with 5 million pages silently never crawled at 0.1% false positives.
- Why the frontier is partitioned by HOST and each host owned by one region, so politeness survives three fetch regions.
- Why a bad normaliser cannot be rolled back with the code, and how the exact urls table makes the filter rebuildable in about forty minutes.
How to read this board
- Diagram, following the loop: START · ONCE, then THE FRONTIER (queue, politeness scheduler, trap detector), then FETCH with POLITENESS beneath it.
- Then EXTRACT and DEDUP on the right, OUTPUT · OFF THE LOOP below them, and the long wires back from the seen set through the trap detector to the frontier - that return is the system. Press play for the eight-step walkthrough.
- Page 1 · Requirements - the questions that change the design: how many pages, how fresh, and whether JavaScript must be rendered.
- Pages 2 and 3 · Capacity and Storage estimation - the politeness arithmetic that breaks the freshness target, and the Bloom filter sizing.
- Page 4 · Availability - why 99% is the right target for a batch system, and which state cannot be rebuilt.
- Page 5 · How it works - the loop in prose - then Page 6 · Deployment plan: host ownership by region, shadowed normaliser rollouts, and the rollback that does not undo.
- The DATA MODEL at the bottom: hosts, urls, pages and links - the exact record behind the probabilistic one.
- Then the conversation to have: the seen set can only be wrong in the direction nothing notices, and politeness and freshness cannot both be met for the largest sites.
1 · 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