System design · Politeness, dedup, the URL frontier

How to design a web crawler

A web crawler downloads pages, pulls out links and repeats, for billions of pages. Keep a prioritised URL frontier with per-host politeness queues, deduplicate URLs with a Bloom filter and store pages in object storage. 1 billion pages a month is about 400 fetches a second, and a Bloom filter over 10 billion URLs is only about 12 GB.

Updated · 5 min read

Seeds and the recrawl scheduler feed the frontier, which hands URLs to fetchers. Fetchers use cached robots.txt and DNS, store pages in S3 and queue them for parsing and dedup.

Web Crawler architecture diagram

Seeds and the recrawl scheduler feed the frontier, which hands URLs to fetchers. Fetchers use cached robots.txt and DNS, store pages in S3 and queue them for parsing and dedup.

The short version

  • The fetch rate is modest. The hard limit is politeness: about one request at a time per host.
  • Priority queues pick what matters; per-host queues decide which host is ready.
  • The URL-seen check runs 50 times per page, so it is an in-memory Bloom filter.
  • Page bodies go to object storage, per-URL metadata to a key-value store.

Clarifying questions to ask first

  • What is the crawl for? (Assume a general-purpose crawler feeding a search index, not an archive or a price monitor.)
  • How many pages, and how fast? (Assume 1B pages a month, about 400 pages a second on average.)
  • Render JavaScript? (Assume no: raw HTML only. Ranking and the index are out of scope.)
  • What are the politeness rules? (Obey robots.txt, and send no more than about one request at a time to a single host.)

Numbers that shape the design

These are assumptions, stated out loud. The point is the order of magnitude, which decides the architecture.

QuantityAssumptionResult
Fetches1B pages a month≈ 400 pages/s average, plan for ≈ 1,000/s
Bandwidth≈ 100 KB per page, compressed≈ 40 MB/s ≈ 320 Mbit/s average
Page storage100 KB × 1B pages≈ 100 TB a month, before keeping old versions
Links found≈ 50 links per page, most already seen≈ 20,000 URL checks/s
Seen URLs10B known URLs, Bloom filter at 1% false positives≈ 12 GB of bits, fits in memory

100 TB a month is a storage bill, not a query problem, so pages go to object storage.

Internal interfaces

A crawler has no public API, only internal calls.

frontier.next(worker_id) -> { url, host, priority, lease_id }
frontier.add(urls[], source_url) -> { accepted, skipped_seen }
frontier.complete(lease_id, status, next_crawl_at)

fetcher.fetch(url) -> {
  status: 200,
  final_url: "https://example.com/a",
  content_hash: "sha256:9f2c...",
  simhash: "0x8a3f1c...",
  s3_key: "pages/2026/10/06/9f2c....html.gz",
  links: [ ... ]
}

A worker that crashes never calls complete, its lease expires, and the URL goes back into the frontier. It is the same visibility-timeout idea SQS uses.

Data model

Page bodies are large and written once, so they go to S3. Per-URL metadata is small and looked up by key, so it fits a key-value store such as DynamoDB.

url_state            key: url_hash
  url                text
  host               text
  last_crawled_at    timestamp
  next_crawl_at      timestamp
  last_status        int
  content_hash       text       exact-duplicate check
  simhash            bigint     near-duplicate check
  change_count       int        how often the page actually changed
  s3_key             text       latest stored copy

host_state           key: host
  robots_txt         text
  robots_fetched_at  timestamp
  crawl_delay_ms     int
  ip                 text       cached DNS answer
  next_allowed_at    timestamp

Normalise before hashing: lowercase the host, drop default ports, fragments and tracking parameters. Otherwise the same page gets crawled under ten URLs.

High-level design

  • Fetcher workers on EC2 take URLs from the frontier, check robots.txt and the DNS cache, and write the body to S3.
  • A parser extracts links and computes fingerprints, in the same worker or behind an SQS queue so slow parsing doesn't hold up fetching.
  • Dedup drops links already seen and pages whose content is a duplicate. New URLs go back to the frontier.
  • A recrawl scheduler sets next_crawl_at and re-adds URLs when they come due.

URL frontier and politeness

One FIFO queue fails because pages link mostly to their own site: a hundred workers hit one server, which returns 429s or blocks your IP range while the rest of the web waits.

Front queues sort URLs by priority (link popularity, domain importance, change rate), and higher queues are pulled more often. Back queues each hold one host, and a heap keyed on next_allowed_at says which host is ready. Respect Crawl-delay and stretch the delay when a host slows down. Throughput comes from many hosts in parallel. Huge sites get their own back queues; small hosts share.

Cache robots.txt per host for about a day, and DNS answers too; a lookup can take longer than the fetch. Keep the frontier in a durable store with only queue heads in memory.

Duplicates, recrawls and traps

Check each normalised URL against a Bloom filter. A "no" is always right, so most new links are confirmed in memory; a "maybe" goes to url_state for the exact answer. Hash page bodies so mirrors are stored once. Pages that differ only by a timestamp or ad have different hashes, so use simhash, which gives similar text fingerprints that differ in a few bits.

A news homepage changes every few minutes; an old blog post may never change. Track change_count and adapt. Traps generate endless URLs: a calendar with "next month" forever, session IDs in every link. Cap URL length, path depth and pages per host per cycle, and flag hosts whose new URLs keep producing near-duplicate content.

Common traps

  • Adding politeness later as a rate limit. Per-host queues have to be in the frontier from the start.
  • Lowercasing the whole URL during normalisation. The path can identify a different page; lowercase only the host.
  • Loading every pending URL into RAM. Billions of pending URLs don't fit; keep durable queues with ready heads in memory.
  • Fetching robots.txt and resolving DNS for every page. Cache host-level answers with an explicit refresh policy.
  • Using the URL hash as the content fingerprint. Different URLs can return the same page; keep separate identities.

Follow-up questions interviewers ask

  • "What does a Bloom filter false positive cost?" A new URL looks seen, so it is rechecked or skipped.
  • "How do you decide when to recrawl?" Recrawl sooner when the content hash changed last time, later when it didn't.

Frequently asked questions

What is a URL frontier?

+

The crawler's to-do list, ordered by priority and split per host for politeness.

Why use a Bloom filter for URL dedup?

+

It answers "seen before?" from memory using about 10 bits per URL. It never misses a URL it has seen, and a rare false positive only means a new page is skipped or rechecked.

What is the difference between a content hash and simhash?

+

A content hash such as SHA-256 matches only identical pages. Simhash gives similar fingerprints for similar text, so pages that differ by an ad or a date are caught as near-duplicates.

Now fix it yourself.

Run the design under real traffic and see what breaks first. No signup.