KatInterview

Build a Distributed Crawler for Billions of Pages

System DesignModel answer
MediumModel answerSystem Designsystem-designweb-crawlerdistributed-systems

Last updated

Design a distributed system that discovers, fetches and stores web pages at scale while avoiding repeats, honoring site rules, throttling per host, and surviving failures.

You are asked to design a crawler that keeps finding and downloading web pages without stopping, starting from a small set of known URLs and growing outward through the links it discovers.

The system must:

  • Start from seed URLs and scale to a very large number of pages.
  • Not fetch the same thing twice, and respect each site's robots.txt and a per-domain request rate limit.
  • Favor pages that are important or likely to have changed.
  • Persist downloaded content together with its metadata.
  • Tolerate machine failures and be able to pick up where it left off.

Out of scope: search ranking and executing heavy client-side JavaScript.

What to cover in your answer:

  1. Assumptions and a rough capacity estimate.
  2. The main components and how data moves between them.
  3. How you schedule URLs (priority and politeness).
  4. How you detect duplicate URLs and duplicate content.
  5. How you handle recrawling, failures and hostile or pathological sites.
  6. Key trade-offs.

Hints

Hint 1

Start with numbers: pages per month, average page size, and what that implies for fetch rate, bandwidth, storage and the size of the set of known URLs.

Hint 2

Partition work by host. If one node owns a host, throttling, robots and DNS caching become local decisions instead of distributed coordination.

Hint 3

Split the URL scheduler into two layers: one that orders URLs by importance, and one that enforces a minimum gap between requests to the same host.

Hint 4

Treat duplicates at two levels (normalized URL, and page body), and plan for traps such as infinite calendars or session-ID URLs.