LOAD-BEARINGfree
Architecture labTier 13 · unit 15 of 31

Web crawler

Fetch a billion pages a month, extract their links, and keep going — without fetching the same URL twice, without hammering any single site, and without losing the frontier when a worker dies. Nothing here is request-driven; the system is its own only user.

Envelope1B pages/month · politeness per host · a seen-set of 10B URLs

What the design must do

  • A frontier of URLs to fetch, durable across worker restarts
  • Membership test before enqueueing, so a URL is never fetched twice
  • Politeness enforced per host, not globally
  • Raw pages stored as bytes; extracted links fed back into the frontier

The worked envelope

Assumed. 1B pages a month, average page 100 KB of HTML, ~50 outbound links per page, one request per host per second, a year of accumulated history.

Worked envelope
Fetch rate1B ÷ 2.6M s ≈ 385 pages/s, peak ~800/s
Bandwidth385 × 100 KB ≈ 38 MB/s = ~300 Mbps
Raw stored100 TB/month, ~4:1 compressed = 25 TB/month
Link candidates385 × 50 = 19k URLs/s to test for membership
Seen set, exact10B URLs × ~100 B = 1 TB
Seen set, Bloom10B at 10 bits each ≈ 12.5 GB, ~1% false positive
Hosts in flight1 req/host/s to sustain 385/s → ≥385 hosts concurrently

What the numbers decide. Three hundred megabits is an unremarkable amount of bandwidth, and 385 fetches a second is not a demanding rate. So this is not a throughput problem — which is exactly what makes it interesting, because two other numbers are doing all the work.

The first is 19,000 membership tests a second against a set of ten billion. As an exact structure that is a terabyte and a disk seek per test, which is the single most expensive thing in the design; as a Bloom filter it is twelve gigabytes of RAM. The second is the last row: politeness is enforced per host, so sustaining any meaningful rate requires hundreds of distinct hosts in flight at once. Together they say the frontier cannot be one queue and the seen-set cannot be a table — and that is the whole architecture.

The decisions, and what each one costs

A Bloom filter in front of the frontier for the seen-set

Because
19k membership tests/s against 10B URLs is 12.5 GB of RAM as a probabilistic structure and a terabyte with a disk seek per test as an exact one
The cost
False positives mean roughly one page in a hundred is silently never fetched, and you cannot remove an entry once added
Rejected
A unique index on a URL table, which is correct, and puts a random disk seek on the hot path 19,000 times a second

Frontier partitioned by host, with a worker leasing one host at a time

Because
Politeness is a per-host constraint, so it has to be a per-host scheduling decision; a global queue interleaves hosts arbitrarily and sends bursts at whoever happens to be popular
The cost
A site with millions of pages becomes a long-running single-threaded queue, so per-host fairness and caps are now your problem
Rejected
One global FIFO with a rate limiter in front, which either throttles the whole crawl to one host’s speed or fails politeness

Raw pages to object storage, metadata in a key-value store

Because
25 TB a month of bytes nobody queries by content belongs in the cheapest thing that holds bytes, while status, fetch time and content hash are small and looked up by key
The cost
Two systems with no transaction between them, so orphaned objects need a sweeper
Rejected
Storing HTML in the database, which turns 25 TB/month into backup, replication and buffer-pool pressure for data that is never queried

robots.txt fetched once per host and cached with a TTL

Because
It is the difference between a crawler and an abuse complaint, and re-fetching it per URL would multiply request volume against the hosts you are trying to be polite to
The cost
A stale cache means crawling something that was disallowed minutes ago; a host that blocks robots.txt needs a default policy
Rejected
Ignoring it, which gets your address blocked and is the fastest way to end the project

Recrawl scheduled by observed change frequency, not round-robin

Because
A news front page changes hourly and an archived document never does; uniform recrawl spends most of the budget re-fetching bytes that are identical to last time
The cost
You need a change signal per URL and a priority queue rather than a FIFO, and a page that suddenly starts changing is found late
Rejected
Fixed-interval recrawl, which is simpler and spends the majority of a 1B-page budget confirming nothing happened

Components in the reference design

Worker
Async consumer, background jobs
Queue
Work distribution, one consumer per message
Cache
Redis / Memcached, sub-ms lookups
Object Store
S3-style blobs, media, backups
NoSQL Store
Wide-column or document, horizontal scale
Rate Limiter
Token bucket per API key
DNS
Name resolution, GeoDNS routing

What not to draw

  • CDN, Client — A CDN caches your responses for users, and this system serves no users — it is entirely autonomous, so there is no client and no response to cache. Drawing either one usually means the workload has been read as request-driven.

The reference design

The frontier is the system. Everything else is plumbing around one question: which URL next? It has to be durable (a worker dying must not lose work), partitioned by host (politeness is per host), and prioritised (not all URLs are worth the same). A queue per host, with hosts themselves scheduled by a fairness policy, is the shape that satisfies all three.

Dedup before enqueue, not before fetch. The test belongs at the moment a link is extracted, because 19k candidates a second is where the volume is — most extracted links are ones you have already seen. Normalise first (lowercase host, strip fragments, sort query parameters, resolve relative paths) or you will store the same page under six spellings and the membership test will honestly report that it has not seen any of them.

Politeness is a per-host token bucket, and it is not optional. Lesson 9.03’s rate limiter, pointed outward instead of inward: one request per host per second, backing off when a host returns 429 or 503. This is the constraint that makes the crawl slow, and the design has to work with it rather than around it — which is why hundreds of hosts run concurrently rather than one host quickly.

Workers are stateless and interchangeable. Lease a host, fetch, store, extract, enqueue, release. A crash loses one lease, which expires (Lesson 13.27’s delayed queue, exactly). Because at-least-once is what leases buy you, storing a page must be idempotent — key the object by content hash or normalised URL, never by an incrementing id.

Traps that specifically catch crawlers. Infinite spaces: a calendar with a "next month" link generates URLs forever, so depth and per-host page caps are load-bearing rather than tidy. Duplicate content: the same page reachable at many URLs, which a content hash catches after fetching and canonical tags catch before. And crawler traps that generate pages specifically to waste your budget, which is why per-host caps exist at all.

What this is not. There is no user, no request path, and no latency budget — a page fetched two seconds later is not worse. That inverts the instincts every other lab in this tier has trained: nothing here is optimised for tail latency, and everything is optimised for throughput per unit of politeness and for not doing work twice.