KatInterview

Design a Distributed Web Crawler at Scale

System DesignModel answer
MediumModel answerSystem Designdistributed-systemscrawlingurl-frontier

Last updated

Design a fault-tolerant, distributed web crawler that discovers, fetches, parses, and stores billions of pages while respecting site politeness rules.

Distributed Web Crawler

A web crawler is the foundation of any search engine or large-scale content analysis pipeline. Your task is to design one that can operate continuously at internet scale.

What the system must do

  • Accept seed URLs, fetch each page, extract outbound links, and continue crawling discovered URLs.
  • Re-visit pages periodically, prioritizing pages that change frequently or carry high importance.
  • Respect each site's robots.txt file, honor crawl-delay directives, and never overwhelm any single host.
  • Persist crawled content and metadata for downstream consumers such as a search indexer.

What the system must handle well

  • Scale: billions of pages, continuous operation over weeks or months.
  • Politeness: no site should be hit faster than it allows.
  • Fault tolerance: individual node failures or transient network errors must not require a full restart.
  • Robustness: spider traps, malformed HTML, enormous responses, redirect chains, and near-duplicate or exactly-duplicate content.
  • Observability: operators need visibility into crawl progress, error rates, and host-level health.

What to cover in your answer

  1. Back-of-envelope sizing — state your assumptions and derive the numbers that drive your design choices.
  2. High-level architecture — components, data flow, and how they connect.
  3. URL frontier design — how you balance priority with per-host politeness.
  4. URL deduplication — how you avoid re-crawling or re-storing the same URL.
  5. Fetching layer — async I/O, DNS, robots.txt handling, timeouts, and conditional requests.
  6. Parsing and content deduplication — link extraction, exact duplicates, near-duplicates.
  7. Storage — what you store, where, and in what format.
  8. Failure handling and retries.
  9. Monitoring and operational concerns.

A strong answer sizes the problem first, spends most of its depth on the URL frontier and politeness design (the parts candidates most often under-design), and clearly separates URL deduplication from content deduplication. Trade-offs and concrete numbers are expected throughout.

Hints

Hint 1

Start with numbers. Derive pages/second, bandwidth, and the size of the seen-URL set before drawing any boxes. Those numbers will justify every major architectural choice that follows.

Hint 2

The URL frontier is two distinct structures layered together: a priority layer that decides what to crawl next, and a per-host politeness layer that decides when it is safe to crawl it. Design both explicitly and explain how URLs move between them.

Hint 3

URL deduplication (have we seen this URL before?) and content deduplication (have we stored this page before?) are separate problems that require different data structures. A Bloom filter in front of a sharded key-value store handles URL dedup; SimHash handles near-duplicate content.