Video in progress

Strong Middle 🏗️ System design

How do you design a web crawler: which page to fetch when, how not to overload sites, and how to avoid duplicates?

The core is the URL frontier: a queue grouped by domain, with a per-domain rate limit (politeness) and respect for robots.txt. Seen URLs go in a Bloom filter or hash set, content duplicates are detected with a hash/simhash, and the fetcher, parser and storage scale separately.

📖 Answer

The flow:

seed URLs -> URL frontier -> fetchers -> parser -> new URLs -> filter -> frontier
                                         \-> store content (object storage) + index

The frontier isn't a plain FIFO. If 10 thousand pages of one domain sit in the queue back to back, 100 fetchers hit that site at once and take it down (or you get blocked). So:

  • separate queues per domain, with each domain assigned to one (or a few) fetchers at a time;
  • a wait between requests for each domain, and the Crawl-delay and disallowed paths in robots.txt are respected;
  • priority: how important the page is and how fast it changes (a news site every hour, an old blog once a month).

Duplicates come in two kinds:

  • at the URL level — ?utm_source=..., #anchor and letter case are normalized, then "seen?" is checked in a Bloom filter;
  • at the content level — the same page under different URLs. A content hash for exact duplicates, simhash for nearly identical pages.

There are traps too: endless calendar pages (/calendar?month=... is infinite), URLs with session IDs. You set a depth limit and a per-domain page limit.

On scale: fetchers are I/O-bound — with virtual threads or an async HTTP client, one machine holds thousands of parallel connections. Caching DNS is a must, otherwise the DNS server becomes a bottleneck. The frontier state has to live on disk (or in Kafka/a DB) — so the crawler doesn't start from scratch when it restarts.