01

Requirements & scope

Problem Statement & Requirements

Functional Requirements

  • Given a set of seed URLs, systematically crawl the web by following hyperlinks
  • Download and store web page content (HTML, and optionally images/PDFs)
  • Discover new URLs from crawled pages and add them to the crawl frontier
  • Respect robots.txt and crawl-delay directives (politeness)
  • Handle deduplication — don't crawl the same page twice
  • Support prioritized crawling (important pages first)
  • Re-crawl pages periodically to detect changes

Non-Functional Requirements

  • Scalability — crawl billions of pages (the web has ~5 billion indexable pages)
  • Throughput — crawl 1,000+ pages/second per worker, 100K+ pages/second cluster-wide
  • Politeness — never overload a single web server; respect rate limits
  • Robustness — handle malformed HTML, spider traps, infinite loops, timeouts
  • Extensibility — pluggable modules for content extraction, URL filtering, storage backends
  • Freshness — detect and re-crawl changed pages on a schedule

Out of Scope

  • Full-text indexing and search ranking (that's the search engine design)
  • Rendering JavaScript-heavy SPAs (requires headless browser — discussed briefly)
  • Image/video content analysis
02

Scale estimations

Scale Estimations

Web Scale

MetricValue
Total web pages (indexable)~5 billion
Target crawl coverage1 billion pages / month
Pages / day~33 million
Pages / second~385
With burst / parallelism headroom~1,000 pages/second
Re-crawl cycle (popular pages)Every 1-7 days
Re-crawl cycle (long-tail)Every 30 days

Storage

MetricValue
Average page size (HTML only)100 KB
Average page size (compressed)20 KB
Storage per month (1B pages)1B × 20 KB = ~20 TB
Metadata per URL~500 bytes (URL, hash, timestamps, priority)
URL metadata storage (1B URLs)1B × 500 bytes = ~500 GB
URL frontier (pending URLs)~100M URLs × 200 bytes = ~20 GB

Network

MetricValue
Bandwidth (downloads)1,000 pages/s × 100 KB = ~100 MB/s
DNS lookups / second~1,000 (cached heavily)
Outbound connections~5,000 concurrent (with connection pooling)

Hardware

MetricValue
Crawler workers50-100 machines
Pages per worker per second10-20
Storage nodes20-30 machines (2 TB SSD each)
DNS cache nodes2-3 machines
03

Layered architecture

Phase 1 of 4 · Client & edge

Start with the entry points

First, define who uses the system and where requests enter. This is the boundary of the design, not yet a complete request path.

Seed URLs
Begin with a bounded set of known URLs and a defined crawl scope.
Architecture after phase 1. Includes Seed URLs.
Phase 1 — Start with Seed URLs.SVGSVGEditable diagramEditable diagram

This first layer defines the system boundary. The next chapters add application logic and data dependencies. After examining the request paths and tradeoffs, we will add operational safeguards and bring the complete architecture together.

04

API & contracts

Phase 2 of 4 · Application & compute

Add the application logic

Keep the entry points and add the services that do the work. Give each service a clear responsibility before defining its contracts. Storage and background dependencies come next.

URL frontier
Separate freshness priority from per-host scheduling to preserve crawl politeness.
Crawler workers
Respect robots directives and per-domain concurrency limits before fetching.
HTML parser
Extract outgoing links and normalize them before adding newly discovered URLs.
Architecture after phase 2. Includes Seed URLs, URL frontier, Crawler workers, HTML parser. Seed URLs connects to URL frontier. URL frontier connects to Crawler workers. Crawler workers connects to HTML parser.
Phase 2 — Added URL frontier, Crawler workers, HTML parser. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

The frontier hands a worker a URL with a lease, host policy, and attempt count. The worker returns a fetch outcome, content reference, and discovered links. Treat a lost acknowledgement as a possible duplicate fetch, not proof that the page was never stored. Keep URL identity and content identity separate: different addresses can serve the same page.

05

Data model

Phase 3 of 4 · Data & async work

Connect data and background work

The services now need their dependencies: durable state, fast lookups, or work that continues outside a request. Separate these responsibilities rather than treating every component as a database.

Deduplication
Avoid repeated URLs and duplicate content while accounting for canonicalization tradeoffs.
Content storage
Persist page bodies separately from crawl timestamps, status codes, and link metadata.
DNS cache
Reuse DNS answers to reduce lookups while respecting expiry and address changes.
Architecture after phase 3. Includes Seed URLs, URL frontier, Crawler workers, HTML parser, Deduplication, Content storage, DNS cache. Seed URLs connects to URL frontier. URL frontier connects to Crawler workers. Crawler workers connects to HTML parser. HTML parser connects to Deduplication. HTML parser connects to Content storage. Crawler workers connects to DNS cache.
Phase 3 — Added Deduplication, Content storage, DNS cache. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

Content Storage

Content Storage
Content StorageSVGSVGEditable diagramEditable diagram
06

Core design decisions

URL Frontier — The Heart of the Crawler

Two-Level Queue Architecture

The frontier must balance two competing goals:

  1. Priority — crawl important pages first
  2. Politeness — don't hammer any single domain
Two-Level Queue Architecture
Two-Level Queue ArchitectureWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Priority Calculation

Priority Calculation
Priority CalculationSVGSVGEditable diagramEditable diagram
07

Request flows

Crawl Workflow — Step by Step

Single Page Crawl Flow

Single Page Crawl Flow
Single Page Crawl FlowWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Crawler Worker Internal Pipeline

Crawler Worker Internal Pipeline
Crawler Worker Internal PipelineSVGSVGEditable diagramEditable diagram
08

Performance & caching

URL Deduplication

The Challenge

  • Billions of URLs to track
  • Must check every extracted URL against "already seen" set
  • Different URLs can point to the same content

URL-Level Deduplication (Before Fetching)

URL-Level Deduplication (Before Fetching)
URL-Level Deduplication (Before Fetching)SVGSVGEditable diagramEditable diagram

Content-Level Deduplication (After Fetching)

Content-Level Deduplication (After Fetching)
Content-Level Deduplication (After Fetching)SVGSVGEditable diagramEditable diagram

DNS Resolution

DNS Resolution
DNS ResolutionSVGSVGEditable diagramEditable diagram
09

Advanced design

Politeness — robots.txt & Rate Limiting

robots.txt Handling

robots.txt Handling
robots.txt HandlingSVGSVGEditable diagramEditable diagram

Per-Domain Rate Limiting

Per-Domain Rate Limiting
Per-Domain Rate LimitingSVGSVGEditable diagramEditable diagram

BFS vs DFS Traversal

BFS vs DFS Traversal
BFS vs DFS TraversalSVGSVGEditable diagramEditable diagram

Distributed Coordination

Partitioning the Crawl Across Workers

Partitioning the Crawl Across Workers
Partitioning the Crawl Across WorkersSVGSVGEditable diagramEditable diagram

Coordination Service (Zookeeper / etcd)

Coordination Service (Zookeeper / etcd)
Coordination Service (Zookeeper / etcd)SVGSVGEditable diagramEditable diagram

Re-Crawl Strategy (Freshness)

Re-Crawl Strategy (Freshness)
Re-Crawl Strategy (Freshness)SVGSVGEditable diagramEditable diagram

Handling JavaScript-Rendered Pages

Handling JavaScript-Rendered Pages
Handling JavaScript-Rendered PagesSVGSVGEditable diagramEditable diagram
10

Edge cases

Spider Traps & Robustness

Spider Traps & Robustness
Spider Traps & RobustnessSVGSVGEditable diagramEditable diagram
11

Tradeoffs

Tradeoffs & Design Decisions Summary

DecisionOption AOption BChosenWhy
TraversalDFSBFS (priority-based)Priority BFSDiscovers important pages first; DFS gets trapped easily
PartitioningBy URL hashBy domainBy domainNatural politeness enforcement; DNS/robots.txt cache locality
URL dedupHashSet (exact)Bloom filter + DBBloom + DB12.5 GB bloom filter handles 99.2% of checks in memory
Content dedupSHA-256 onlySHA-256 + SimHashSHA-256 (primary) + SimHash (batch)Exact dedup is fast; near-dedup runs as offline job
StorageS3 onlyHDFS onlyHDFS (hot) + S3 (archive)Fast access for indexing; cheap long-term archival
DNSSystem resolverCustom multi-level cacheMulti-level cache95%+ cache hit rate; pre-fetch for queued domains
PolitenessFixed delayAdaptive (response-time based)Adaptive + robots.txtRespects slow servers; obeys explicit directives
JS renderingAlways renderSelective renderSelective10x cost; only ~30% of pages need it
CoordinationCentralized queueZookeeper + consistent hashZookeeper + consistent hashDecentralized work distribution; resilient to worker failure
Re-crawlFixed scheduleAdaptive (change-rate based)AdaptiveChanged pages crawled more often; saves bandwidth
Frontier persistenceIn-memory onlyRedis/disk-backedRedis (sorted sets)Survives worker restarts; shared across workers
12

Reliability & fault tolerance

Phase 4 of 4 · Operations & resilience

Add operational safeguards

With the request paths and tradeoffs established, add the controls that help detect trouble and keep the system operating. The final diagram retains every layer introduced so far.

Crawl control
Monitor queue age and host failures; cap depth and repeated URL patterns to contain spider traps.
Architecture after phase 4. Includes Seed URLs, URL frontier, Crawler workers, HTML parser, Deduplication, Content storage, DNS cache, Crawl control. Seed URLs connects to URL frontier. URL frontier connects to Crawler workers. Crawler workers connects to HTML parser. HTML parser connects to Deduplication. HTML parser connects to Content storage. Crawler workers connects to DNS cache. URL frontier connects to Crawl control.
Phase 4 — Added Crawl control. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

Monitoring & Operational Concerns

Monitoring & Operational Concerns
Monitoring & Operational ConcernsSVGSVGEditable diagramEditable diagram
13

Production architecture

High-Level Architecture

High-Level Architecture
High-Level ArchitectureSVGSVGEditable diagramEditable diagram

Detailed Component Architecture

Detailed Component Architecture
Detailed Component ArchitectureWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Production Architecture

Production Architecture
Production ArchitectureWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram
14

Further exploration

Try crawling a site with an infinite calendar: every page links to tomorrow. A larger cluster only wastes resources faster. Set a crawl budget, identify repetitive URL patterns, and decide when a new page is worth revisiting. Then introduce a small site that changes hourly and compare the scheduling priorities.

15

Interview playbook

Interview Tips

  1. Start with the crawl loop — "Fetch → Parse → Extract URLs → Enqueue → Repeat." Draw this first, then expand each box.

  2. Politeness is critical — Interviewers look for this. Show the two-level frontier (priority + per-domain queues), robots.txt caching, and adaptive delays.

  3. Deduplication has two layers — URL-level (before fetch, bloom filter) and content-level (after fetch, SHA-256/SimHash). Mention both.

  4. Discuss spider traps — This shows real-world awareness. Calendar pages, infinite pagination, and redirect loops are common examples.

  5. Partition by domain, not URL — Explain why: politeness enforcement is automatic, DNS cache locality, no distributed rate limiter needed.

  6. BFS, not DFS — Quick explanation: BFS discovers high-value pages near the root first. DFS goes deep into one site and misses breadth.

  7. Don't forget DNS — A crawler does more DNS lookups than almost any other system. Multi-level caching (in-process → shared → resolver) is essential.

  8. Re-crawl strategy — "How do you keep content fresh?" Adaptive scheduling based on change frequency + conditional HTTP requests (If-Modified-Since).

  9. Scale the numbers — Walk through: 1B pages/month → 33M/day → 385/second → 1000/s with headroom → 50-100 workers. This shows you can think quantitatively.

  10. Mention WARC format — If storage comes up, mentioning the Web ARChive standard shows domain knowledge. "We'd batch pages into WARC files to avoid the small-file problem on HDFS."