Design Case StudiesExpert17 min read2 questions

Design a Web Crawler and Search Index

Crawling billions of pages politely, deduplicating near-identical content, and building an inverted index that answers a query in under 200 ms.

Covers: Crawl frontier, politeness, deduplication, inverted index, sharding strategies, ranking, index freshness

This case study covers two systems that happen to be adjacent: a massively parallel, politeness-constrained crawler, and a distributed inverted index. They test completely different skills, which is exactly why interviewers like it.

  • Crawl: 10 B pages, refreshed monthly ≈ 4,000 pages/s sustained.
  • Storage: 10 B × 100 KB compressed ≈ 1 PB of raw content.
  • Index: inverted index roughly 10–20% of corpus size ≈ 100–200 TB.
  • Query: p99 under 200 ms across the full corpus.
  • Politeness: never overwhelm a host - typically at most one request per host per second, and always respect robots.txt.
Filter
0/2 mastered
ExpertcrawlerfrontierpolitenessAsked at Google, Bing

30-second answer

The core structure is a URL frontier: a set of per-host queues with a scheduler that guarantees at most one in-flight request per host, so politeness is enforced by the data structure rather than by hoping workers behave. Deduplicate at three levels - exact URL after canonicalisation, exact content by hash, and near-duplicate content by SimHash, since a huge fraction of the web is boilerplate variations of the same page. Store the frontier durably and partition it by host hash so each worker owns a disjoint set of hosts and no cross-worker coordination is needed.

Expertinverted indexsearchshardingAsked at Google, Elastic

30-second answer

An inverted index maps each term to a posting list of the documents containing it, with positions and frequencies. A query intersects the posting lists of its terms and ranks the results. Shard by **document** rather than by term: each shard holds a complete index over a subset of documents, so every query fans out to all shards, each returns its top-k, and a coordinator merges them. Term sharding looks appealing because a query only touches a few shards, but it creates catastrophic hotspots on common terms and makes multi-term intersection require cross-shard traffic.

Showing 2 of 2 questions for design-a-web-crawler-and-search.

Check your understanding

4 questions · no sign-up, nothing stored

0/4 answered
Question 1

1.Why shard a search index by document rather than by term?

Question 2

2.How should crawler politeness be enforced?

Question 3

3.What catches printer-friendly variants of the same article?

Question 4

4.In a fan-out query across 100 shards, what determines total latency?

Hands-on challenge

Build it - this is what you talk about in a deep-dive round.

Build a small crawler and search index

Crawl 100,000 pages from a permitted seed set and build a searchable inverted index. Scale down, but keep every architectural decision.

Requirements

  • Implement a per-host frontier that structurally enforces politeness and respects robots.txt.
  • Implement all three deduplication levels and report how many pages each caught.
  • Build an inverted index with positions, and implement BM25 scoring.
  • Shard the index across at least three processes with a fan-out coordinator.
  • Measure p50 and p99 query latency and identify the dominant cost.

Stretch goals

  • Add skip pointers and measure the intersection speedup.
  • Add an incremental index for newly crawled pages and merge it periodically.