# 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 seen set is a Bloom filter, so it is wrong in…

Source: https://tierslate.com/templates/web-crawler

Infrastructure primitives · System design · core · 8 step walkthrough · 4 tables

Why a crawler that feeds on its own output needs politeness, deduplication and loop brakes more than speed.

**Own this board: 400 credits.** The first act plays on the page. 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

1. Diagram, following the loop: START · ONCE, then THE FRONTIER (queue, politeness scheduler, trap detector), then FETCH with POLITENESS beneath it.
2. 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.
3. Page 1 · Requirements - the questions that change the design: how many pages, how fresh, and whether JavaScript must be rendered.
4. Pages 2 and 3 · Capacity and Storage estimation - the politeness arithmetic that breaks the freshness target, and the Bloom filter sizing.
5. Page 4 · Availability - why 99% is the right target for a batch system, and which state cannot be rebuilt.
6. 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.
7. The DATA MODEL at the bottom: hosts, urls, pages and links - the exact record behind the probabilistic one.
8. 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

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.

- 5 written pages
- 8 walkthrough steps
- 4 tables (30 columns)

5 pages behind this one:

- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan

## Related system design templates

- [URL shortener system design](https://tierslate.com/templates/url-shortener) - Why one tiny write and a hundred cacheable reads make two systems sharing a single table.
- [Distributed cache system design](https://tierslate.com/templates/distributed-cache) - Why a hash ring moves a sliver of keys when a node leaves, and why the hot key and the miss storm remain.
- [Key-value store system design](https://tierslate.com/templates/key-value-store) - How a key finds its replicas, and why choosing how many to wait for buys overlap rather than order.
- [Rate limiter system design](https://tierslate.com/templates/rate-limiter) - Why the hard part of limiting requests is where the shared counter lives, not the algorithm.
- [Unique ID generator system design](https://tierslate.com/templates/unique-id-generator) - How 64 bits buy sortable ids with no central counter, and what happens when the clock goes backwards.
- [Pastebin system design](https://tierslate.com/templates/pastebin) - Why storing text is the easy part and expiry, abuse and the read path are the design.
- [Load balancer system design](https://tierslate.com/templates/load-balancer) - How requests are spread across servers, and why the health check matters more than the algorithm.
- [API gateway system design](https://tierslate.com/templates/api-gateway) - Why auth, routing and limits move to one front door, and what that door costs when it falls over.
- [Login and sessions system design](https://tierslate.com/templates/login-sessions) - How a password becomes a session, and what changes when the session is a signed token nobody can revoke.
- [Feature flags system design](https://tierslate.com/templates/feature-flags) - Why a flag is evaluated locally from a pushed ruleset, and what a stale ruleset does during an incident.
- [Secrets manager system design](https://tierslate.com/templates/secrets-manager) - How secrets are encrypted under a key nobody holds directly, and why rotation is the feature, not storage.
- [DNS system design](https://tierslate.com/templates/dns-resolver) - How a name becomes an address through layers of caches, and why the TTL decides how fast a mistake spreads.
- [Distributed cron system design](https://tierslate.com/templates/cron-scheduler) - Why a scheduled job needs a lease so it runs once, not once per server, and what a missed tick should do.
- [Background job queue system design](https://tierslate.com/templates/job-queue) - Why a job queue delivers at least once, and how idempotent workers and dead letters keep retries honest.
- [Code execution sandbox system design](https://tierslate.com/templates/code-execution-sandbox) - How untrusted code is run in isolated, time-limited sandboxes, and why the queue in front of them is the real system.
- [Distributed log system design](https://tierslate.com/templates/message-queue) - Why an append-only partitioned log gives ordering and replay, and what replication and consumer offsets cost.
- [Consensus system design](https://tierslate.com/templates/raft-consensus) - How Raft keeps replicas agreeing through elections and a replicated log, and what a network partition really does.
- [Object storage system design](https://tierslate.com/templates/object-storage) - How objects are split, erasure-coded and placed across failure domains so losing disks never loses data.

All 100 system design templates: https://tierslate.com/templates (Markdown: https://tierslate.com/templates.md)
