Crawl the Web from One Seed Across a 1,000-Machine Fleet
System DesignModel answerLast updated
Design a distributed crawler that starts from one seed URL and spreads work over 1,000 machines, covering coordination, balancing, failure handling, and growth.
Problem
You have a fleet of 1,000 commodity machines. Design a crawler that begins with one seed URL and uses the whole fleet to discover and download pages by following links.
Walk through your design as you would in a system design discussion. Cover:
- Requirements and assumptions. Scope (open web vs. one domain), what is stored, when the crawl is "finished", and what etiquette rules apply (robots.txt, per-host politeness).
- Scale estimates. Pages, throughput per machine, storage, link volume, and the size of the "already seen" structure.
- Architecture. How URLs are assigned to machines, what each machine runs, and how machines exchange newly found links.
- Coordination. How membership, work assignment, and termination detection work.
- Load balancing. How you keep work even, including very large hosts and machines of different capacity.
- Fault tolerance. What happens when machines crash, messages are lost, or the network partitions.
- Scalability follow-ups. What changes if the fleet grows 10x, the target grows 10x, or you must re-crawl for freshness.
State your assumptions explicitly and justify the trade-offs you make.
Hints
Hint 1
Do the arithmetic first: with about a billion pages and tens of outlinks each, a single central 'seen URLs' service cannot keep up. Ask what partitioning the seen set implies about who owns each URL.
Hint 2
Think about what to hash. Hashing by host rather than by full URL makes politeness, robots.txt caching and DNS caching local to one machine, and keeps most links local. What problem does that create for very large hosts?
Hint 3
Termination is subtle: an empty local queue does not mean the crawl is over, because a batch of URLs may still be on the wire. Think about counting messages sent and received, and about what happens to in-flight work when a machine dies.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify scope
- Target: the open web, optionally restricted by a domain filter, starting from a single seed. HTML only.
- Output: page bodies in a blob store plus the discovered link graph.
- Done means: the reachable set is exhausted or a page/depth budget is hit.
- Rules: honor robots.txt, limit request rate per host, tolerate machine failures.
- Non-functional goals: very few duplicate fetches, even load, near-linear scaling, no single point of failure.
2. Back-of-the-envelope
| Quantity | Estimate |
|---|---|
| Target pages | 1B |
| Pages per machine | ~1M |
| Fetch rate per machine | ~20 pages/s (async, I/O bound) |
| Crawl duration | 1M / 20 ≈ 14 hours |
| Storage | ~100 KB/page, so ~100 TB total, ~100 GB per machine |
| Link volume | ~50 outlinks/page, so ~50B link discoveries |
| Seen set | 1B × 8-byte fingerprint = 8 GB total, ~8 MB per machine if sharded |
A single dedup service would face tens of thousands of lookups per second and several GB of state. Sharded 1,000 ways, each shard is tiny and fits in memory. That points to hash-partitioned ownership.
3. Core design: each host has one owner
owner(url) = ring.lookup(hash(normalize(url).host))
Using consistent hashing on the host rather than the full URL gives:
- Local politeness. One machine sees all traffic to a host, so rate limiting needs no distributed lock.
- Cached robots.txt and DNS once per host.
- Locality. Most links point to the same host and never leave the machine.
The cost is skew: a giant site can overload its owner. Use ~100 virtual nodes per machine for general smoothing. For known hot hosts, split by host + hash(path) mod k across several machines while sharing a rate budget for that host.
Per-machine components
- Frontier: a queue per host with a
next_allowed_time, plus a priority layer on top (Mercator-style front/back queues). - Seen set: in-memory set or Bloom filter of fingerprints for owned URLs, checkpointed to disk.
- Fetcher pool: async HTTP with timeouts, bounded retries and a robots cache.
- Parser: extract links, normalize (lowercase host, drop fragments, resolve relative paths, sort query params), compute a content hash to spot near-duplicates.
- Router: local URLs go to the local frontier; remote URLs are batched per destination (flush every N URLs or T ms). Batching converts billions of tiny messages into a manageable RPC rate.
- Storage writer: pages go to a blob store keyed by URL hash, so rewrites are idempotent.
Flow
The seed goes to its owner, which fetches and parses it and routes the outlinks. Each receiver dedups against its own seen set before enqueuing. The crawl fans out from there.
4. Machine-to-machine interface
SubmitUrls(batch[{url, depth, source}]) -> ack
Heartbeat(id, frontier_size, fetch_rate, epoch) -> membership_view
GetStatus() -> {pending, in_flight, fetched, sent, received}
Dedup happens at the owner, so SubmitUrls is idempotent and safe to retry.
5. Coordination
Recommended: small control-plane cluster (etcd/ZooKeeper, 3 to 5 nodes) responsible only for membership, the ring and its epoch, and termination detection. It is never in the data path, so it cannot bottleneck throughput.
Alternative: fully decentralized. Gossip membership (SWIM), a ring derived from the member list, and a distributed termination algorithm (Dijkstra–Safra). More resilient, harder to reason about; choose it only if no central infrastructure is allowed.
Termination. A crawl is finished when every machine has an empty frontier and nothing in flight, and no batches are in transit. Each machine reports cumulative sent and received counts; the coordinator declares completion when all are idle and global sent equals global received in two consecutive polling rounds.
6. Load balancing
- Static: consistent hashing with virtual nodes, weighted by machine capacity.
- Dynamic: heartbeats report queue depth and fetch rate. For persistent overload, the coordinator reassigns some virtual nodes, transfers the matching frontier and seen entries, and bumps the epoch.
- Hot hosts: sub-partitioning as above, with a shared per-host token bucket.
- Backpressure: a receiver whose queue is full rejects or delays batches so senders slow down rather than exhaust memory.
7. Fault tolerance
- Detection: missed heartbeats mark a machine dead; the coordinator removes it, bumps the epoch, and its ranges move to ring successors.
- Recovery: machines checkpoint frontier and seen set to durable storage and keep a write-ahead log of accepted batches. The new owner loads the checkpoint and replays the log. Without shared storage, replicate each shard to R successors.
- Semantics: at-least-once. Work that was in flight at crash time is requeued; a few duplicate fetches are fine because storage writes are idempotent.
- Sender buffering: unacknowledged batches are retried, and stale-epoch messages are redirected to the current owner.
- Partitions: a machine that loses contact with the coordinator stops fetching after a lease expires, preventing two owners from hitting the same host.
- Crawler traps: cap depth, URL length and per-host page counts; detect calendar-style infinite URL spaces.
8. Scalability follow-ups
- 10x machines: the ring absorbs new nodes by moving only about 1/N of the keys; the control plane is unaffected because it carries no data traffic.
- 10x pages: seen-set memory grows; switch to a Bloom filter plus on-disk exact store, or an LSM-backed set. Bandwidth and storage are the real limits.
- Freshness: add re-crawl scheduling driven by observed change rate and page importance, and use conditional GETs (ETag, If-Modified-Since).
- Priority: score URLs (link depth, host quality) so the frontier crawls valuable pages first.
Common mistakes
- Putting a central seen-URL database in the data path.
- Hashing on full URL, which scatters a host's requests and breaks politeness.
- Declaring termination from local queue emptiness alone.
- Forgetting skew, crawler traps, or idempotency of retries.
- Sending one RPC per discovered link instead of batching.