System design interview: design a web crawler
A web crawler starts from a set of seed URLs, downloads each page, pulls out the links and adds the new ones to a queue called the URL frontier. The interview is about four things: how the frontier decides what to fetch next, how you stay polite to each website, how you avoid fetching the same page or content twice, and how a crawl of billions of pages survives machines failing halfway through.
By Evin JohnPublished 7 min read
1. Clarify the requirements
"Design a web crawler" can mean a search engine's crawler, a price monitor for a few thousand shops, or a one-off archive job. Each has a different answer, so ask what the crawl is for before you draw anything.
- Purpose: feeding a search index (breadth, freshness) or a narrow job such as monitoring competitors (depth on a few sites)?
- Content types: HTML only, or also PDFs, images and pages that need JavaScript to render?
- Scale and freshness: how many pages, and how often must a page be re-crawled? News sites change hourly, most pages rarely.
- Constraints: must obey robots.txt and keep the load on any single site low. Assume both even if the interviewer does not mention them.
- Out of scope unless asked: ranking, the search index itself, and logging in to sites.
2. Estimate the scale
State round numbers as assumptions. These are illustrative figures for a large general-purpose crawler, not any real search engine's.
| Quantity | Assumption | Result |
|---|---|---|
| Pages per month | 1 billion | about 385 pages a second on average, plan for 2x at peak |
| Average page size | 100 KB of HTML | about 100 TB of raw HTML a month |
| Five years of storage | keep raw pages, compressed about 4x | roughly 1.5 PB |
| URLs discovered | about 30 new links per page | the frontier grows far faster than you can fetch, so it must prioritize |
| Distinct hosts | tens of millions | politeness state (last fetch time, robots rules) must be sharded too |
The numbers tell you two things. Throughput per machine is not the issue; a few dozen fetcher machines can sustain 800 pages a second. The frontier is the issue: it holds billions of URLs, most of which you will never fetch, so it needs disk-backed storage and a way to choose.
3. The crawl loop
- Input
- Seed URLs
- Re-crawl scheduler
- Frontier
- Priority queues
- Per-host queues
- Host heap (next allowed time)
- Fetch
- Fetcher workers
- DNS cache
- robots.txt cache
- Process
- Parser and link extractor
- Content fingerprint check
- URL normalizer and seen-set
- Storage
- Raw page store
- Metadata DB
- Frontier checkpoints
- PickA fetcher asks the frontier for the next URL whose host is allowed to be contacted now.
- Resolve and checkResolve the host through a local DNS cache (DNS lookups are slow and are a classic hidden bottleneck), and check the cached robots.txt rules for that path.
- FetchDownload with a timeout and a size cap, follow a limited number of redirects, and record the status code, headers and fetch time.
- ParseExtract links and text. Compute a fingerprint of the content to detect duplicates.
- StoreWrite the page to blob storage and its metadata (URL, fingerprint, last fetched, status) to a database.
- Feed backNormalize each extracted link, drop the ones already seen, and push the rest into the frontier with a priority.
4. The URL frontier, the core of the design
A single FIFO queue fails in two ways. It fetches unimportant pages as readily as important ones, and because pages link heavily within their own site, it sends bursts of requests to one host. The standard fix, described in the Mercator crawler paper, splits the frontier into two layers.
- Front queues (priority). A prioritizer gives each URL a score: how important the site is, how often the page changes, how deep it is from the home page. URLs go into one of several queues by score, and a selector drains high-priority queues more often.
- Back queues (politeness). Each back queue holds URLs for exactly one host. A heap ordered by "earliest time this host may be contacted again" tells fetchers which queue to take from next. After each fetch, that host's next allowed time moves forward by the crawl delay.
- Disk, not memory. Billions of URLs do not fit in RAM. Keep the head of each queue in memory and the rest in an append-only log or a key-value store, loaded in batches.
next_allowed[host] = last_fetch_finished[host] + max(robots_crawl_delay, k * last_response_time)
# k around 10: if a server took 300 ms to answer, wait about 3 s before
# the next request to it. Slow servers get crawled more gently.5. Deduplication: URLs and content
Duplicates waste most of a naive crawler's budget. Handle them at two levels.
| Problem | Example | Technique |
|---|---|---|
| Same URL written differently | HTTP://Example.com:80/a/../b?utm_source=x | Normalize: lowercase scheme and host, drop default ports, resolve dot segments, strip tracking parameters and fragments, then check a URL-seen set |
| URL-seen set too big for memory | Tens of billions of URLs | A Bloom filter in front of a sharded on-disk set: false positives skip a few new URLs, which is acceptable; false negatives cannot happen |
| Different URLs, identical page | Mirrors, session IDs in URLs, print versions | Hash the normalized content (exact duplicates) and store the hash per page |
| Different URLs, nearly identical page | Same article with a different ad or date | SimHash or MinHash fingerprints; pages within a few bits are treated as duplicates |
6. Scaling out
- Partition by host. Hash the host name to pick the node that owns it. That node holds the host's back queue, politeness timer and robots cache, so no cross-node locking is needed. Links to other hosts are forwarded to their owners in batches.
- Fetchers are stateless. They can be added or removed freely; they only need the frontier node to hand them work.
- Storage splits by access pattern. Raw pages go to cheap blob storage; per-URL metadata (last fetched, fingerprint, status) goes to a wide-column or key-value store keyed by URL hash.
- Geography. Crawling a site from a data center near it cuts latency, so large crawlers run fetchers in several regions and route hosts accordingly.
7. Freshness and re-crawling
A crawler never finishes; it revisits. Track how often each page actually changed (compare fingerprints across fetches) and schedule the next visit by that rate: a front page that changes hourly is revisited hourly, an archive page monthly. Conditional requests with If-Modified-Since or an ETag let servers answer "not modified" cheaply. Sitemaps and push protocols such as IndexNow tell you directly which URLs changed, which is far cheaper than guessing.
8. Failure modes
| Failure | Effect | Mitigation |
|---|---|---|
| Frontier node crashes | Its hosts stop being crawled; in-memory queue heads are lost | Checkpoint queues to durable storage every few minutes; reassign the host range to another node and replay from the checkpoint |
| Fetcher dies mid-download | A URL is taken but never finished | Lease URLs with a timeout; an unacknowledged lease returns to the queue |
| A site slows down or returns 5xx | Requests pile up against it | Back off exponentially for that host, using the adaptive delay above |
| DNS resolver overloaded | Every fetch stalls | Local caching resolvers per fetcher pool, asynchronous lookups |
| Spam and link farms | Budget spent on worthless pages | Lower the priority of hosts with low-quality signals; cap pages per host |
9. Trade-offs to discuss
- Breadth-first or best-first. Breadth-first is simple and finds many sites; best-first by importance gets valuable pages sooner. Real crawlers use priorities, with breadth as a tie-breaker.
- Render JavaScript or not. A headless browser sees content that plain HTML fetching misses, but costs ten to a hundred times more per page. Render only the hosts that need it.
- Exact or approximate seen-set. A Bloom filter is small and fast but occasionally skips a new URL. For a search crawler that is fine; for a compliance archive it may not be.
- Store everything or only changes. Keeping every version supports history and diffing, at a large storage cost.
10. How to talk through it in the interview
Fictional example
- Candidate
- That is the basic loop: frontier, fetch, parse, back to the frontier. If I stop there, the crawler would send hundreds of requests a second to whichever site links to itself the most.
- Interviewer
- So how do you prevent that?
- Candidate
- I would split the frontier in two. Priority queues decide what matters, and per-host queues with a heap of next-allowed times decide when each site can be hit again. Then I will cover duplicates and what happens when a frontier node dies.
- Draw the loop first, then spend most of the time on the frontier.
- Mention robots.txt and politeness without being asked; it signals real-world awareness.
- Have a concrete answer for traps and for crash recovery: they are the usual follow-ups.
Rehearsing the crawler question out loud
System design is a spoken exercise, so practice it that way. Have a friend read the prompt on a video call, or record yourself answering it. Natively transcribes the session live and can sketch the architecture as a diagram while you talk, so afterwards you can check whether you actually explained the frontier's two layers or only drew boxes. The saved transcript shows where you spent your minutes; most candidates find they spend too long on the fetch step and too little on duplicates.
For the neighbouring questions, the rate limiter uses the same per-key timing idea as crawl politeness, and the job scheduler covers leases and retries in more depth. For a design where the hard part is contention rather than breadth, try the ticket booking system.
Questions people ask
What is the URL frontier in a web crawler?
It is the queue of URLs waiting to be fetched. Large crawlers split it into priority queues, which decide what matters most, and per-host queues with a timer, which make sure no single website is contacted too often.
How does a web crawler avoid duplicate pages?
It normalizes URLs and checks them against a seen-set (often a Bloom filter backed by disk), and it fingerprints page content with a hash or SimHash so different URLs serving the same page are stored once.
How do crawlers stay polite to websites?
They obey robots.txt, keep one queue per host, and wait between requests to the same host, often longer when the server responds slowly. They also back off on errors.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
