Case study V.6Intermediate

Design a Web Crawler

A crawler is a loop: take a URL, fetch it, extract its links, repeat. At a billion pages the hard parts are staying polite to every website, never fetching the same thing twice, and surviving the strange corners of the web.

The short answer

Requirements. Start from seed URLs, follow links, store pages for indexing, recrawl pages as they change and obey robots.txt; never overload a website, scale to hundreds of fetchers, and survive broken HTML, slow servers and crawler traps.

Fetch rate
385 pages per second1B pages a month, peak about 800
Storage
500 TB a month1B pages × 500 KB
URLs seen
about 12 GB10B URLs in a Bloom filter at 1%

The design. A URL frontier decides what to fetch and when: front queues order URLs by priority, and a router keeps one back queue per host, so a fetcher takes a host’s next URL only after its politeness delay. Fetchers download, parsers extract links, and every link is normalized and checked against a Bloom filter of URLs already seen. Content is checked too: a checksum catches exact copies and SimHash catches near duplicates. Depth limits and per host budgets stop crawler traps.

Interview prompt

Design a web crawler that collects a billion pages a month for a search engine.

Requirements and estimates

Functional requirements

  • Start from seed URLs and follow links.
  • Store page content for indexing.
  • Recrawl pages according to how often they change.
  • Obey robots.txt.

Non-functional requirements

  • Politeness: never overload any single website.
  • Scales to hundreds of fetcher machines.
  • Robust to broken HTML, slow servers and crawler traps.
  • Extensible to new content types such as PDFs.

Estimates

Fetch rate  1B pages ÷ 2.6M s per month         ≈ 385 pages/s, peak ≈ 800
Storage     1B × 500 KB                         = 500 TB per month, ≈ 30 PB in 5 years
URL seen    10B URLs in a Bloom filter at 1%    ≈ 12 GB of memory

Whiteboard

What you sketch in the first five minutes: the loop itself, then the queues that keep it polite.

1. The loop

Say: a crawler is a loop; the design is everything that keeps it polite and finite.

URL frontierfetchpagesextract linksnormalizeseen before?no: queue ityes: drop ita Bloom filter of 10B URLs, 12 GB385 pagesa second
  1. Take a URL from the frontier and fetch the page.
  2. Store it, extract its links and normalize them.
  3. Drop the links a Bloom filter has seen, and queue the rest.

Next question: DNS turns out to be the bottleneck. Cache lookups per host on each fetcher.

2. One queue per host

Say: front queues decide what matters, back queues decide when.

front: what mattersback: whenhighmidlowroutera.comb.orgc.netheap of next allowed timeshostnext fetchb.orgnowa.comin 1 sc.netin 3 sfetchertakes b.org’s next URL
  1. The prioritizer puts important, often changing pages first.
  2. A router keeps one back queue per host.
  3. A heap of next allowed times says which host may be fetched again.

Next question: one slow server ties up a fetcher. Tight timeouts, and its own back queue keeps the delay to that host.

The URL frontier

Front queues decide what matters, back queues decide when. The prioritizer ranks URLs by importance and how often the page changes. The router keeps one back queue per host, and a fetcher may take that host’s next URL only after its politeness delay has passed, tracked in a heap of next allowed times.

Never twice

Same URL

Normalize first: lowercase the host, drop fragments, sort query parameters, strip tracking parameters. Then check a Bloom filter of URLs already seen. A false positive means a page is occasionally skipped, which is acceptable; it never causes a duplicate fetch.

Same content

Mirrors and session parameters serve identical pages under many URLs. A checksum of the content catches exact copies; SimHash catches near duplicates, such as the same article with a different ad block.

TrapWhat happensDefense
Endless calendars“Next month” links foreverMaximum depth and pages per host
Session IDs in URLsEvery visit looks like a new pageStrip known parameters, content dedupe
Generated link farmsPages that link to ever new pagesURL length limits, per host budgets
Slow serversFetchers sit idle waitingTight timeouts; one host per back queue isolates it

What the interviewer probes next

How do you decide when to recrawl a page?

Estimate each page’s change rate from past crawls: news front pages hourly, documentation monthly. Use conditional requests with If-Modified-Since or ETag, so unchanged pages return a 304 with no body.

What about pages built with JavaScript?

Send them to a separate render queue served by headless browsers. Rendering costs far more than fetching, so do it only when the static HTML lacks the content.

How are hosts split across crawler machines?

Hash the hostname to a machine with consistent hashing. One machine then owns all politeness state for a host, and adding machines moves only some hosts.

DNS turns out to be the bottleneck. Why, and what helps?

Each lookup can take tens to hundreds of milliseconds and many resolvers are single threaded. Run a caching resolver on every crawler machine and respect record TTLs.

Building blocks used here

Want to run this as a mock interview? See interview prep.

© 2026 Arman Ajabkhani · armantik.com · Privacy