KatInterview

Crawl the Web from One Seed Across a 1,000-Machine Fleet

System DesignModel answer
HardModel answerSystem Designdistributed-systemsweb-crawlerconsistent-hashing

Last 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:

  1. 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).
  2. Scale estimates. Pages, throughput per machine, storage, link volume, and the size of the "already seen" structure.
  3. Architecture. How URLs are assigned to machines, what each machine runs, and how machines exchange newly found links.
  4. Coordination. How membership, work assignment, and termination detection work.
  5. Load balancing. How you keep work even, including very large hosts and machines of different capacity.
  6. Fault tolerance. What happens when machines crash, messages are lost, or the network partitions.
  7. 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.