Skip to content

Design a Web Crawler

A system design interview walkthrough for a web crawler, covering the URL frontier, politeness, duplicate detection, crawl traps and recrawl scheduling.

Intermediate24 minUpdated 2 December 2026

Before this: Bloom Filters & Probabilistic Structures, Message Queues

"Design a web crawler" starts with a loop anyone can write: take a URL from a queue, download the page, extract its links, add the new ones to the queue. The interview begins when you ask what that loop does to the internet and to itself.

Run it naively and it hammers one small website with thousands of requests a second, gets stuck in an endless calendar of dates, downloads the same article under forty URLs and revisits pages that never change while news sites go stale. Every one of those is a design decision. The interviewer is testing whether you can name them: politeness, duplicate detection, traps and freshness, with a frontier that stays correct across many machines.

This page designs the crawler that feeds a search engine. The search engine question covers what happens to the pages after they are stored.

Clarify the requirements

Functional requirements:

  1. Start from a set of seed URLs and discover pages by following links.
  2. Download HTML pages and store them for later processing (indexing, analysis).
  3. Respect robots.txt and each site's crawl rules.
  4. Revisit pages over time, more often for pages that change often.
  5. Skip pages already seen, whether by the same URL or by the same content.

Out of scope, said aloud: rendering JavaScript-heavy pages (a headless browser costs 10 to 100 times more per page), image and video crawling, the indexing pipeline.

Non-functional requirements:

  • Polite: never overload a site. At most one request per second per host by default, or whatever Crawl-delay and the server's response times suggest.
  • Robust: it meets malformed HTML, endless redirects, hung connections and hostile sites, and must keep going.
  • Scalable: add machines to crawl faster, with no central bottleneck.
  • Extensible: new content types and filters plug in without rewriting the fetch loop.
  • Fresh: important pages are re-fetched sooner than obscure ones.

Estimate the scale

Assume the crawler fetches 1 billion pages a month, with an average page of 100 KB.

Fetch rate: 1,000,000,000 ÷ (30 × 86,400 s) ≈ 385 pages per second.

Bandwidth: 385 × 100 KB = 38.5 MB/s, about 310 Mbps sustained.

Storage: 1B × 100 KB = 100 TB per monthly crawl uncompressed. HTML compresses about 3:1, so roughly 33 TB stored.

Concurrency: one fetch takes about 500 ms (DNS lookup, connection, download). By Little's law, 385 per second × 0.5 s ≈ 190 fetches in flight at once. Ten fetcher machines at 50 connections each is generous.

Discovered URLs: an average page has about 50 links, so 1 billion pages produce 50 billion links. After normalization and deduplication, assume 10 billion unique URLs.

The seen-URL set: storing an 8-byte fingerprint of each of 10 billion URLs takes 10B × 8 B = 80 GB. A Bloom filter at about 10 bits per URL (around a 1% false-positive rate) takes 10B × 10 bits ÷ 8 = 12.5 GB.

Politeness math: at one request per second per host, a single host with 1 million pages takes 1,000,000 s ≈ 11.6 days.

"385 pages per second is modest, so downloading is not the hard part. The frontier is: it must hold billions of URLs, give a different host each fetcher can talk to at every moment, and enforce one request per second per host. Politeness, not bandwidth, caps how fast any one site can be crawled."

The capacity estimator reproduces the 385 pages per second (ignore its storage line, which counts a full year of raw pages).

API and data model

The crawler is a pipeline, so its interfaces are internal.

frontier.add(url, priority)             -> ok
frontier.next(workerId, n)              -> [{ url, host, notBefore }]
robots.allowed(host, path)              -> boolean       (cached per host, 24 h)
store.put(url, fetchedAt, httpStatus, contentHash, body)
frontier   per-host queue:  host -> ordered URLs, nextAllowedAt
seen       fingerprint(normalized URL)  (Bloom filter + persisted shards)
pages      key = fingerprint(url), value = compressed HTML, in object storage
page_meta  (url, last_fetched, content_hash, change_count, next_fetch)

The non-obvious choice: the unit of scheduling is the host, not the URL. Every politeness, DNS and robots.txt decision is made per host, so the frontier is organized by host.

High-level design

The slice to simulate is the fetch loop: seeds enter a frontier queue, a pool of fetchers pulls URLs, checks a seen-URL set and stores each page in object storage.

Seeds enter a frontier queue, a pool of fetchers pulls URLs, checks a seen-URL set and stores each page in object storage.seedsfrontierurl queuefetchersseen urlspage store
Seeds enter a frontier queue, a pool of fetchers pulls URLs, checks a seen-URL set and stores each page in object storage.
  • The frontier accepts URLs and puts them on a queue.
  • A pool of fetchers pulls work from the queue and checks the seen-URL set.
  • Fetched pages are written to object storage.
Describe this diagram

Components

  • seeds (Client)
  • frontier (Service)
  • url queue (SQS queue)
  • fetchers (Service)
  • seen urls (Redis)
  • page store (Object storage (S3))

Connections

  • seeds sends to frontier
  • frontier sends to url queue
  • url queue sends to fetchers
  • fetchers sends to seen urls
  • fetchers sends to page store

Run it, then try cutting the number of consumers on the queue or the visibility timeout, and watch the backlog and redelivery. A fetch that takes longer than the visibility timeout is handed out twice.

The crawl path: a fetcher takes a URL from its frontier shard, checks robots.txt (cached) and resolves DNS (cached), downloads the page with a hard timeout and size cap, stores the body, extracts links, normalizes them and sends each to the frontier. Before a link is queued, the seen-URL set is consulted.

The recrawl path: a scheduler periodically re-adds known URLs whose next_fetch time has passed, at a priority based on how often the page has changed.

The interesting problem: the URL frontier

A frontier that is just one big queue fails in three ways at once. Choose among the designs by what each protects.

Approach A: one FIFO queue

Pop the oldest URL, fetch it, push its links. This is breadth-first search.

Good: trivial to build, and breadth-first reaches important pages early.

Bad: links cluster by site. A page links to 50 pages on the same host, so 50 consecutive pops hit one host, hammering it. There is also no way to prefer important URLs, and nothing stops a trap from filling the queue.

Approach B: priority queues plus per-host queues

Use the Mercator design: a set of front queues ordered by priority (a news homepage outranks a deep forum page), and a set of back queues, one per host, each holding that host's URLs. A worker picks a host whose nextAllowedAt has passed, takes one URL from its queue and sets nextAllowedAt one second ahead.

Good: politeness is enforced structurally: a host is never fetched twice within its delay. Fetchers stay busy by rotating among many hosts, because at any moment thousands of hosts are ready.

Bad: on one machine, the per-host queues and timers outgrow memory, and one machine can serve only so many hosts.

Approach C: shard the frontier by host

Assign each host to a frontier shard by hash(host) mod S, and give each shard to a crawler node that owns that host's queue, timer, robots.txt cache, DNS cache and seen-URL range. A link to another host is sent to the shard that owns it.

Good: all of one host's state lives in one place, so politeness needs no cross-machine coordination. A node can crash and its shard be reassigned. Capacity grows by adding shards, with consistent hashing so a new node does not reshuffle everything.

Bad: one enormous host is pinned to one shard, and a link between shards costs a network hop. For a shard that falls behind, the work does not migrate on its own.

Conceptual diagramFetcherExtract linkshash hostShard 1: host queuesShard 2: host queues
Diagram, as text
  • Fetcher leads to Extract links
  • Extract links leads to hash host
  • hash host leads to Shard 1: host queues
  • hash host leads to Shard 2: host queues
  • Shard 1: host queues leads to Fetcher
  • Shard 2: host queues leads to Fetcher

The recommended answer is C with B inside each shard. Shard by host so that politeness and caches stay local, and inside the shard keep priority front queues and per-host back queues. State the reason in one line: the host is the unit of politeness, so make it the unit of ownership.

The second decision: duplicates and traps

Most of the web is repeated. Three layers of defense keep the crawler from wasting itself.

URL normalization. Before checking anything, canonicalize: lowercase the host, remove default ports and fragments, sort query parameters, drop known tracking parameters (utm_*, session ids). http://Example.com:80/a?b=1&a=2#top and http://example.com/a?a=2&b=1 are the same page.

The seen-URL set. A Bloom filter at 12.5 GB (against 80 GB for exact fingerprints) answers "have we queued this?" in memory. Its only error is a false positive: about 1% of genuinely new URLs are treated as seen and skipped. It never produces a false negative, so a URL is never queued twice. For a crawler, losing 1% of newly discovered URLs, most of which are reachable from other links anyway, is a good trade, and the Bloom filters lesson shows how to size and shard one.

Content fingerprints. Different URLs often serve the same content (mirrors, print views, ?sessionid=). After fetching, hash the main text. An exact hash catches identical pages, and a similarity hash such as SimHash catches near-duplicates, such as the same article with a different sidebar. Skip indexing and following links on duplicates.

Traps. A calendar that links to "next month" forever, or a URL that grows a new path segment on every click, generates infinite unique URLs. Defend with a maximum depth, a cap on URLs per host (say 100,000 unless the host is high-priority), a maximum URL length, and a rule that flags a host whose new pages are mostly near-duplicates.

Bottlenecks and failures

Slow and hung servers. A host that accepts a connection and never answers ties up a fetcher. Set connect and read timeouts (a few seconds), a response size cap (say 10 MB), and back off a host after repeated failures instead of retrying at once.

DNS. At 385 pages per second, uncached lookups add latency and load on resolvers. Run your own resolver cache and keep entries per host, which is natural in a host-sharded design. See DNS for how TTLs affect this.

A crashed fetcher. The URL it was working on must come back. With a queue's visibility timeout or a lease, an unacknowledged URL is redelivered, so fetching must be safe to repeat: the page store is keyed by URL fingerprint, so a second write replaces the first.

A frontier shard falls behind. One shard may own a host with a huge backlog. Watch queue age per shard, and shed low-priority URLs first when the backlog grows rather than stopping the crawl.

Hostile or legal limits. Obey robots.txt (RFC 9309), identify your crawler in the User-Agent with a contact URL, and honor opt-outs. A crawler that ignores these gets blocked or worse.

What if the seen-URL store is down? Fetchers can keep working from the last in-memory state and accept duplicates for a while. A short outage causes some repeated fetches, which is cheaper than stopping.

Trade-offs to name aloud

  • Bloom filter over an exact set: 12.5 GB instead of 80 GB, in exchange for skipping about 1% of new URLs.
  • Sharding by host: local politeness and caches, in exchange for a skewed shard when one host is huge.
  • Politeness over speed: deliberately slow per host, in exchange for not being blocked.
  • Breadth-first with priority: reaches important pages early, in exchange for deep pages arriving late.
  • Skipping JavaScript rendering: a large coverage gap on modern sites, in exchange for 10 to 100 times lower cost per page.

What interviewers listen for

  • A working answer: a queue of URLs, fetchers, a seen set, storage and robots.txt respect.
  • A strong answer: explains politeness with per-host queues and a delay, sizes the Bloom filter against the exact set, and normalizes URLs.
  • A standout answer: also shards the frontier by host and says why, handles crawl traps and near-duplicates (SimHash), designs recrawl from observed change rates and sets fetch timeouts against queue visibility timeouts.

Check your understanding

Common mistakes

Presenting only the fetch loop. Take a URL, download, extract, repeat. This is the question's warm-up, not its answer. Spend your time on the frontier.

One global queue. It cannot enforce per-host politeness or priority, which are two of the four main requirements.

Ignoring robots.txt. Asking permission is not optional. Mention fetching and caching it per host, and honoring Disallow and Crawl-delay.

Exact dedup only, with no memory estimate. 10 billion URLs is 80 GB as fingerprints. Show that you computed it and chose the Bloom filter on purpose.

No defense against traps. Without depth and per-host caps, one calendar widget can consume the crawl budget.

Recrawling everything at the same rate. A news homepage changes every few minutes and an archived PDF never does. Uniform recrawl wastes budget on the second and starves the first.

Practice

One site has 50 million pages and the business wants all of them crawled within a week. At one request per second per host, is that possible, and what do you do?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Divide pages by seconds in a week before you reach for a design change.

Show a strong answer

Do the arithmetic. A week has 604,800 seconds, so one request per second yields 604,800 pages, about 1% of the site. Crawling 50 million pages would take 50,000,000 ÷ 86,400 ≈ 580 days.

Ask the site, not the code. A polite crawler cannot exceed the host's limit. Check Crawl-delay, then contact the site owner for a higher rate. A site that wants to be indexed often will agree, or offers a sitemap and bulk feed.

Raise the rate only on evidence. Adapt the delay to server health: if responses stay fast and there are no errors, you can cautiously increase the rate, and back off at the first sign of strain.

Prioritize and use sitemaps. Crawl the 500,000 most important URLs (by links and traffic) first, use the sitemap's change dates to fetch only what moved, and treat the rest as lower priority.

The pattern worth keeping: when a hard external limit caps throughput, change what you fetch and ask for a better limit, not how fast your own system runs.

How would you decide how often to recrawl each page, given a fixed fetch budget of 385 pages per second?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Pages change at very different rates. What can you measure about each page from past fetches?

Show a strong answer

Measure change per page. On every fetch, compare the content hash with the last one and record whether it changed. Over several visits, each URL gets an estimated change rate.

Schedule from the estimate. A page that changed on 8 of the last 10 visits is re-added after hours, and one that never changed after about ten visits moves to weeks. Cap the interval at a maximum (for example 90 days) so nothing is forgotten.

Weight by importance. Spend budget where freshness is valuable: pages with many incoming links, news and high-traffic hubs. A rapidly changing, unimportant page can be fetched less often than its change rate suggests.

Spend the budget. 385 per second is about 33 million fetches a day. Split it between new discovery and recrawl, say 70/30, and let the scheduler fill each slot by priority. Use If-Modified-Since and ETag so a recrawl of an unchanged page costs a small 304 response.

The pattern worth keeping: drive revisit frequency from measured change rates and importance, then spend a fixed budget in priority order.

Key takeaways

  • The host is the unit of politeness, so make it the unit of scheduling and ownership.
  • A good frontier has priority front queues and per-host back queues, sharded by host.
  • Sizing decides the dedup structure: 10 billion URLs is 80 GB exact or 12.5 GB with a Bloom filter at 1% error.
  • Normalize URLs first, then fingerprint content to catch what normalization misses.
  • Defend against traps with depth, per-host and length caps.
  • Recrawl by measured change rate and importance, not on a uniform schedule.

Further reading

  • A. Heydon and M. Najork, "Mercator: A Scalable, Extensible Web Crawler", World Wide Web journal (1999): the frontier with front and back queues.
  • S. Brin and L. Page, "The Anatomy of a Large-Scale Hypertextual Web Search Engine", WWW (1998): the crawler within an early search engine.
  • G. Manku, A. Jain and A. Das Sarma, "Detecting Near-Duplicates for Web Crawling", WWW (2007): SimHash for near-duplicate pages.
  • M. Koster et al., RFC 9309 "Robots Exclusion Protocol" (2022).

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track