Design a URL crawler
hard 60 minStart from a few addresses, download pages, find links, and repeat a billion times a month.
Numbers that decide
Work out a number when the answer changes what you build.
Capacity
Scale estimates
Pages
Hosts
Links
All numbers, each with its decision
| Quantity | Working | Decision |
|---|---|---|
| Download | 386 × 100 KB = 38.6 MB/s = 309 Mb/s; 926 Mb/s at peak | One network card could do it; we use several machines for failures |
| Raw bytes | 1B × 100 KB = 100 TB a month | Compress before storing |
| Stored | ÷ 8 = 12.5 TB a month, 150 TB a year | Object storage |
| URL records | 10B × 300 B = 3 TB, 9 TB on three copies | A partitioned store |
| Seen set | 10B × 14.4 bits = 18 GB | Fits in memory, 1.8 GB on each of 10 shards |
| Exact 8-byte hashes | 10B × 8 B = 80 GB | Possible too: 8 GB a shard |
| Hot frontier | 100M × 70 B = 7 GB | Memory for the next hours, disk for the rest |
| SimHash | 10B × 8 B = 80 GB, 1.3 TB in 16 tables | Only if near copies matter |
| robots and DNS | 10M hosts × about 300 B = 3 GB | Keep with the host's owner |
Machines
How many connections?
Little's law, with and without timeouts
| Part | Working | Result |
|---|---|---|
| Fetchers | 752 connections, about 1,000 on one asynchronous process | One is enough; run 8 in 4 zones |
| Parsing | 386 × 50 ms = 19 cores; 58 at peak | Six machines of 16 cores, with room |
| Frontier | 30,900 to 92,600 checks and 1,157 leases a second | 10 shards; memory, not CPU, decides |
| DNS | 386 × 5% misses = 19 lookups a second | One local resolver and a spare |
| Waiting work | A 10 minute storage stall at peak: 1,157 × 600 × 12.5 KB = 8.7 GB | Kafka holds it easily |
Money
Small objects are the expensive part
| Item | Working | A month |
|---|---|---|
| One object for each page | 1B PUT × $0.005 per 1,000 | $5,000 |
| Packed, 1 GB files | 12,500 PUT | 6 cents |
| 150 TB, Standard | 50 TB × 22 | $3,350 after a year |
| 150 TB, infrequent access | 150,000 GB × $0.0125 | $1,875 plus reading fees |
| 12.5 KB objects there | Billed as 128 KB each | 10 times the bytes |
What if
Change one number
| If | Then |
|---|---|
| 1 million pages a month | 0.4 pages a second: version 1 is the answer |
| All pages from one host | 86,400 a day, whatever we buy |
| Half are returns and 60% answer 304 | 30% fewer pages to download |
| Every page rendered, 2 CPU seconds each | 772 cores on average, 2,300 at peak: compute is now the limit |
| 100 billion pages a month | 38,600/s; a seen set for 1 trillion URLs is 1.8 TB, so filters split by host and exact sets on disk |
| Trillions | Regions coordinate only through summaries, near-copy search uses locality-sensitive hashing, most URLs are never queued |