Design a Distributed Web Crawler
Design a scalable web crawler to download and index billions of web pages across the internet.
Think of a web crawler like an explorer in a library with billions of cross-referenced books. It reads one book, writes down all the cited titles into a to-read list, and systematically visits each new title.
- Clients
- Seed URLs
- Services
- Crawler service
- Parser
- Queues, caches
- URL frontier
- DNS cache
- Seen filter
- Data, outside
- Web sites
- Page store
1. Requirements and scope
- Crawl web pages starting from seed URLs.
- Extract HTML, extract outbound links, and store raw content in blob storage.
- Respect robots.txt and website politeness policies.
- Scalability: 1 Billion pages per month.
- Be polite: never send so many requests at once that a website slows down.
- Extensibility: Support pluggable document parsers.
2. Back-of-the-envelope numbers
- Writes: 400 pages saved a second, on average (50%)
- Reads: 400 DNS lookups a second (50%)
Balanced: reads and writes are close. Both paths need care, so neither can be slow.
3. API
4. Data model and storage
PAGES: (url_hash, url, content_s3_path, etag, last_crawled_at, status_code)
5. The design, in three versions
Version 1: Single Threaded Crawler
Single script keeping URLs in a local queue and downloading sequentially.
Distributed Web Crawler: Version 1: Single Threaded Crawler Version 1 of 3
The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.
One request, step by step
Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.
- The order of the steps
- A request or its reply
The parts: switch one off
1. Clients
2. Services
3. Queues, caches
4. Data, outside
The steps in words0 of 4 steps shown
Seed URLs to URL frontier
The seed URLs go into a queue in memory.
URL frontier to Crawler service
One fetcher takes the next URL.
Crawler service to Web sites
It downloads the page.
Crawler service to Page store
It saves the page on its own disk.
Write path, read path and failures
Each path follows one request through the final design (version 3), one hop at a time.
Write pathFetch and store one page
- URL frontier
- Worker
- DNS cache
- Web site
- Blob storage
- Bloom filter
URL frontier to Worker
A worker takes the next URL. The frontier only hands out a host that has not been fetched in the last 2 seconds.
Worker to DNS cache
The worker finds the host's IP address in a local DNS cache, so it does not ask DNS for every page.
Worker to Web site
It checks the site's robots.txt rules, then downloads the page.
Worker to Blob storage
It saves the raw HTML and records the page's details.
Worker to Bloom filter
It pulls the links out of the page and asks the filter which ones are new.
Worker to URL frontier
Only the new links go back into the frontier, in the queue for their host.
Read pathChoose the next URL
- Priority queues
- Host queues
- Delay queue
- Worker
Priority queues to Host queues
A router moves URLs from the priority queues into one queue per host. Important pages go first.
Host queues to Delay queue
After a host is fetched, its queue is parked for 2 seconds in a delay queue.
Delay queue to Worker
When the wait ends, the host's next URL is handed to a free worker.
What breaks, and what happens then
A worker crashes in the middle of a page
- What users see
- That URL is not finished.
- What the design does
- The frontier hands a URL out with a time limit. If no result comes back, it hands the URL to another worker.
A site is slow or returns errors
- What users see
- Workers would waste time waiting on it.
- What the design does
- Use short timeouts and retry later with a longer wait. After repeated failures, lower the host's priority.
A spider trap makes endless new URLs
- What users see
- The crawler fills up with useless pages from one site.
- What the design does
- Cap the pages per host and the depth of a URL, so one site cannot take over the crawl.
The Bloom filter gives a false positive
- What users see
- A new URL is treated as already seen and skipped.
- What the design does
- Accept it. At a rate near 1%, a few pages are missed and the filter stays small.
6. Deep dives
7. Follow-up questions
- How do you detect spider traps? (Answer: Limit URL path depth, enforce per-domain maximum page limits, and analyze URL query parameter patterns).
What it costs
Storage dominates: about 500 TB of pages a month. Network traffic comes second. Compress pages, keep only the text you index, and move old copies to a cheaper storage class.
Another way to design it
If you only need a known list of sites, a simple queue with a politeness delay per site is enough. The priority queues and the Bloom filter earn their place only at web scale.
8. How answers are judged
A passing answer at Mid level. A complete design with numbers: about 400 pages a second on average, 1,000 at peak. It explains how already-seen URLs are skipped and goes deep on one part, such as storage or politeness.
| What is judged | Junior | Mid | Senior | Staff |
|---|---|---|---|---|
| BreadthHow much of the system does the answer cover? | Names the core parts: clients, servers, a database and a cache. | Covers the whole main flow, from the request to the stored data and back. | Builds a complete design without being led through it. | Covers the system, the systems around it and who owns each part. |
| DepthHow far does it go into the hard parts? | Explains what each part does and why it is there. | Goes deep on one part, such as the database or the cache. | Goes deep on the two or three riskiest parts. | Goes deepest where the risk is largest, and explains why the risk is there. |
| DrivingWho leads the conversation? | Follows the interviewer, step by step. | Moves forward alone, with an occasional nudge. | Leads the conversation from start to finish. | Changes the problem when the question asked is not the right one. |
| Trade-offsAre choices compared and justified? | Names more than one option. | Says why one option was picked over another. | Compares options in detail, with what each one costs. | Ties each choice to cost, speed and risk for the business. |
| Unclear questionsWhat happens when the question is vague? | Answers the questions that are asked. | Asks questions to make the problem clear. | Sets the scope and says what is left out. | Questions the assumptions behind the problem itself. |
| ScopeWhat does it consider beyond the normal path? | Covers the normal path, when everything works. | Adds what happens when a part fails. | Adds growth: what breaks at ten times the load, and the fix. | Adds abuse, cost and the daily work of running the system. |
Requirements and scope
Before I design, I want to check the scope. We crawl from seed URLs, extract links, and store raw pages; robots.txt and politeness limits are a hard requirement, not optional. I will assume we need to reach 1 billion pages a month, and that duplicate URLs must not be fetched twice.
The crawler starts from a few seed pages, downloads each one, finds the links inside, and adds those links to the queue to fetch next.
Shows: Unclear questionsThe difference: The weak answer never asks about politeness limits, which the problem states as a hard requirement, so it could fetch a site far too fast.
Estimates
1 billion pages a month is about 400 pages a second on average, and 1,000 at peak. At 500 KB a page, that is about 500 TB a month, or 6 petabytes a year. That rules out keeping raw pages on a single disk.
1 billion URLs a month is a lot of links to track. But links are short pieces of text, so storage will not be a real concern.
Shows: DepthThe difference: The weak answer sizes storage for the URLs, not the roughly 500 KB of downloaded content behind each one. That content comes to about 6 petabytes a year.
Core design
A worker fetches a URL, saves the page to blob storage, and extracts its links. Each new link is checked against a Bloom filter of already-seen URLs before joining the queue, so the same page is never queued twice.
Each worker fetches a URL, saves the page to blob storage, and pushes every link it extracts onto the frontier. The frontier keeps one queue per host and waits between requests to the same host.
Shows: DepthThe difference: With no way to check whether a URL was already fetched, the crawler can queue and refetch the same pages. It can even loop forever on a link cycle.
Deep dive
The hard part is not overwhelming one site: workers pulling from one shared queue can all land on the same host at once. I would split the queue per host. A delay queue then releases a host's next URL only after a politeness interval, such as 2 seconds.
I would have a large pool of workers pull from one shared queue of URLs and fetch pages as fast as the pool allows.
Shows: DepthThe difference: A shared queue lets many workers fetch from the same host at once, slamming it with concurrent requests. Per-host queues with a delay enforce politeness instead.
Failures and trade-offs
A page that generates endless new links, such as an infinite calendar, can fill the frontier with junk forever. I would cap the pages crawled per domain and the URL path depth. That way, one such site cannot starve the crawl budget for every other domain.
If a site keeps producing new links, the crawler keeps discovering and fetching them, since more pages found means more of the web gets covered.
Shows: ScopeThe difference: With no per-domain limit, one site that generates endless links can consume the entire crawl budget, starving every other domain.
We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.
10. Check your design with your own AI
Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.
The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.
See the prompt
You are a system design interviewer. Review my design for the interview problem below. Problem: Design a Distributed Web Crawler Design a scalable web crawler to download and index billions of web pages across the internet. What users must be able to do: - Crawl web pages starting from seed URLs. - Extract HTML, extract outbound links, and store raw content in blob storage. - Respect robots.txt and website politeness policies. How well it must work: - Scalability: 1 Billion pages per month. - Be polite: never send so many requests at once that a website slows down. - Extensibility: Support pluggable document parsers. Numbers to assume: - 1 Billion pages crawled per month = ~400 pages/sec continuous download. Judge my design at the Mid level. A passing answer at this level: A complete design with numbers: about 400 pages a second on average, 1,000 at peak. It explains how already-seen URLs are skipped and goes deep on one part, such as storage or politeness. For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each: 1. Requirements and scope 2. Estimates 3. Core design 4. Deep dive 5. Failures and trade-offs Then ask me the two follow-up questions an interviewer would ask next. Do not write a full model answer for me. My design: [Describe your parts, how one request moves through them, and why you chose each one.]