Skip to content
All problems

Design a web crawler

breadth · 45 min · senior/staff

Setting

You're building the crawler that feeds a search index: given a set of seed URLs, discover and fetch web pages at scale, extract links and content, and keep the index reasonably fresh without hammering any one site.

The ask

Design the system that crawls the web starting from a seed set, discovers new URLs from fetched pages, and re-crawls pages on a freshness schedule.

Constraints & scale

  • Target throughput: ~1B pages/month; billions of URLs in the frontier at steady state
  • Politeness: no more than a few requests/sec to any single host, honoring robots.txt and crawl-delay
  • Avoid re-crawling unchanged content wastefully, but detect and re-fetch pages that change frequently (news) faster than ones that don't (archives)
  • Must not crawl the same URL twice concurrently, and must dedupe near-identical URLs (tracking params, session ids)
  • A single malicious or misconfigured site (infinite link mazes, crawler traps) must not consume a disproportionate share of the fleet

What a strong answer covers

Requirements → estimates (frontier size, fetch rate) → data model (URL frontier, dedupe, content store) → high-level diagram → 1–2 deep dives → trade-offs. Likely probes: how the frontier is partitioned/prioritized per host, dedupe/near-duplicate detection, and the crawl-trap defense.

A 45-minute plan

  1. 0-5 min · Requirements
  2. 5-10 min · Estimates/API
  3. 10-25 min · High-level
  4. 25-40 min · Deep dive
  5. 40-45 min · Wrap

What to cover, in order

  1. Requirements
  2. Estimates (frontier size, fetch rate)
  3. Data model (URL frontier, dedupe, content store)
  4. High-level diagram
  5. 1–2 deep dives
  6. Trade-offs

Where the follow-up questions go

Pick one of these for your deep dive before the interviewer picks for you.

  • How the frontier is partitioned/prioritized per host
  • Dedupe/near-duplicate detection
  • The crawl-trap defense

Key trade-offs

Decisions a strong answer weighs, and what pushes each one either way.

  • Frontier structure. One global priority queue is simple and makes per-site politeness an extra check. Queues partitioned by host build politeness in and need a scheduler to pick between hosts. At a billion pages a month, a host-aware structure is closer to a requirement than an optimisation.
  • Breadth-first or priority-driven. Breadth-first covers the web evenly and wastes effort on low-value pages. Prioritising by importance, change rate or link signals finds valuable content sooner and requires computing those signals and avoids starving the rest.
  • URL dedup structure. Storing every seen URL exactly is certain and large. A Bloom filter is compact and occasionally says a new URL was seen, so you miss a page. Choose based on how costly a missed page is against memory at billions of URLs.
  • Content dedup. Exact hashes catch identical pages. Near-duplicate detection such as fingerprinting catches templated pages and costs more per page. Doing it saves index space and crawl effort.
  • Recrawl policy. A fixed interval is easy and over-fetches static pages. Adapting the interval to observed change finds updates sooner for less bandwidth and needs history per URL. Conditional requests with validators reduce the cost of a check.

Common mistakes

What goes wrong most often on this problem, and why it hurts.

  • No per-host rate limit. A fast crawler overloads small sites, gets blocked and damages its reputation. Honour robots.txt and a per-host delay.
  • Only depth limits against traps. A site can generate unlimited URLs at shallow depth. Cap pages per host, watch for URL patterns and repeated content, and normalise parameters.
  • Exact URL matching only. Tracking parameters, session ids, fragments and case differences produce many URLs for one page. Canonicalise before checking whether you have seen it.
  • Fetching and parsing in one tightly coupled step. A slow site holds a worker, and a parse failure loses the fetch. Separate fetch, parse and link extraction through queues.
  • Not handling failure and politeness over time. Hosts that time out or return errors need backoff and retry limits, or the crawler spends its capacity on dead sites.

Graded on

Requirements & scoping · Estimation · API & data model · High-level architecture · Deep dive · Scalability & performance · Reliability & consistency · Trade-offs · Operability · Communication & drive

Ready to run this one for real?

Try this problem free

Your first session is free. Sign in, and you land on this brief, ready to start.