# Design a Web Crawler

> Crawl billions of pages politely and efficiently with a URL frontier, deduplication, robots.txt handling, distributed workers and storage. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/system-design/case-web-crawler
Last updated: 2026-11-28

Crawl billions of pages politely and efficiently with a URL frontier, deduplication, robots.txt handling, distributed workers and storage.

Advanced · about 4 hours · difficulty 4/5

Learn first: [Message Queues and Async Processing](https://www.internhack.in/roadmaps/tracks/system-design/message-queues), [Indexes and Storage Engines](https://www.internhack.in/roadmaps/tracks/system-design/indexing), [Object Storage and Large Files](https://www.internhack.in/roadmaps/tracks/system-design/object-storage)

A web crawler (the first stage of a search engine, or a price monitoring tool) downloads pages, extracts links and keeps going. It tests your thinking about queues, dedup, politeness and scale.

### Requirements

- Start from seed URLs, fetch pages, extract links, store content for indexing.
- Billions of pages, refreshed periodically; some sites much more often than others.
- **Politeness**: respect robots.txt and do not overload any one host.
- Robust to traps, broken HTML, slow servers and duplicate content.

### Core components

1. **URL frontier**: the to-crawl queue. Usually two levels: **priority queues** (by page importance and freshness need) feeding **per-host queues**, with each host assigned to one worker so you can enforce a delay between requests to the same host.
2. **DNS resolver cache**: DNS lookups are slow; cache them aggressively.
3. **Fetchers**: many async workers downloading pages with timeouts and size limits.
4. **Parser**: extract text and links, normalise URLs (lowercase host, strip fragments, resolve relative paths).
5. **URL seen check**: a large **Bloom filter** or a distributed key-value set of hashes, so each URL is crawled once per cycle.
6. **Content dedup**: hash page content (or use SimHash for near-duplicates) to skip mirrors.
7. **Storage**: raw pages in object storage, metadata (URL, last crawled, hash, status) in a wide-column store.

### Scaling

Partition the frontier and the seen set by **host hash** so each worker owns a set of hosts. Scale workers horizontally. Re-crawl scheduling uses how often a page changed in the past.

### Traps and safety

Infinite calendars, session IDs in URLs and auto-generated pages create **crawler traps**. Limit depth per site, URL length and pages per host, and detect repeating patterns.

### Pitfalls

- A single global FIFO queue that hammers one host with thousands of parallel requests.
- Ignoring robots.txt and getting blocked or worse.

You are ready to move on when you can explain how your frontier enforces politeness per host while keeping thousands of workers busy.

## Key concepts

- **URL frontier with priority and host queues**
- **Politeness and robots.txt**
- **URL normalisation**
- **Bloom filter for seen URLs**
- **Content dedup and SimHash**
- **DNS caching**
- **Crawler traps**
- **Re-crawl scheduling**

## Mini project

Build a polite crawler that respects robots.txt, uses per-host queues with a 1 second delay, dedups URLs with a Bloom filter and stores pages to disk. Crawl a few thousand pages from a seed set you are allowed to crawl and report pages per second and duplicates skipped.

## Check yourself

Why does the URL frontier need per-host queues instead of a single global queue?

## Free resources

- [About robots.txt](https://www.robotstxt.org/) (robotstxt.org)
- [How Google Search works](https://developers.google.com/search/docs/fundamentals/how-search-works) (Google)
- [Common Crawl](https://commoncrawl.org/) (Common Crawl)
- [Bloom filter](https://en.wikipedia.org/wiki/Bloom_filter) (Wikipedia)

Previous: [Design a Distributed Cache](https://www.internhack.in/roadmaps/tracks/system-design/case-distributed-cache) · Next: [Design Search Autocomplete (Typeahead)](https://www.internhack.in/roadmaps/tracks/system-design/case-search-autocomplete)

## More in HLD Case Studies: Core Building Blocks

- [Design a URL Shortener (TinyURL, bit.ly)](https://www.internhack.in/roadmaps/tracks/system-design/case-url-shortener)
- [Design a Distributed Rate Limiter](https://www.internhack.in/roadmaps/tracks/system-design/case-distributed-rate-limiter)
- [Design a Notification System](https://www.internhack.in/roadmaps/tracks/system-design/case-notification-system)
- [Design a Distributed Cache](https://www.internhack.in/roadmaps/tracks/system-design/case-distributed-cache)
- [Design a Web Crawler](https://www.internhack.in/roadmaps/tracks/system-design/case-web-crawler)
- [Design Search Autocomplete (Typeahead)](https://www.internhack.in/roadmaps/tracks/system-design/case-search-autocomplete)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [System Design Roadmap](https://www.internhack.in/roadmaps/tracks/system-design)
