Skip to main content
BLUEPRINT #03Storage & Search

Design a Web Crawler at Scale

Target AWS Architecture:DynamoDBS3ElastiCacheSQS
10-Stage Structure:1. Requirements→2. Sizing→3. Topology→4. Data Model→5. AWS Topology→6. Deep-Dive→7. Failures→8. SRE Playbooks

1. Problem Statement & Scope Clarification

System Mission

Design a distributed, fault-tolerant, planetary-scale web crawler (similar to Googlebot, Bingbot, and Common Crawl) capable of crawling 1 Billion web pages per month, respecting domain politeness and robots.txt specifications, eliminating duplicate URLs and near-duplicate content, and persisting raw web snapshots into for downstream search indexing and LLM training pipelines.

Functional Requirements

  1. Scalable Distributed Crawling: Crawl billions of web pages starting from a curated set of seed URLs, traversing outbound hyperlinks up to a bounded depth.
  2. Politeness & robots.txt Compliance: Respect domain crawl-delays, disallow directives, and cap request rates to a maximum of 1 request per second per target host.
  3. URL & Content Deduplication:
    • URL Deduplication: Avoid re-fetching visited URLs within a 30-day freshness window.
    • Near-Duplicate Content Detection: Detect identical or template-modified mirror pages using 64-bit SimHash fingerprints.
  4. HTML Parsing & Link Extraction: Extract canonical URLs, page titles, text content, and outbound links, normalizing relative paths to absolute URI standards.
  5. Durable Web Archive Storage: Persist raw HTML and WARC (Web ARChive) formatted files into Standard-IA.

Non-Functional Requirements (SLAs & SLOs)

  • Scale: 1 Billion pages/month (β‰ˆ400Β pages/sec\approx 400\text{ pages/sec} sustained, Peak: 1,200Β pages/sec1,200\text{ pages/sec}).
  • Fault-Tolerance: 100% resilient to worker container termination via AWS EC2 Spot Instances (70βˆ’90%70-90\% compute cost reduction).
  • Extensibility: Modular architecture supporting pluggable media downloaders and headless browser rendering (Playwright) for JavaScript-heavy single-page applications.

2. Capacity & Scale Estimation (Back-of-the-Envelope Math)

Ingestion & Throughput Derivations

  • Monthly Target: 1,000,000,000Β pages/month1,000,000,000\text{ pages/month} (1 Billion pages/month).
  • Average Crawl Rate: SustainedΒ CrawlΒ Rate=109Β pages30Β daysΓ—86,400Β secβ‰ˆ386Β pages/sec\text{Sustained Crawl Rate} = \frac{10^9\text{ pages}}{30\text{ days} \times 86,400\text{ sec}} \approx \mathbf{386\text{ pages/sec}}
  • Peak Crawl Rate (3Γ—3\times multiplier): PeakΒ CrawlΒ Rate=386Γ—3β‰ˆ1,200Β pages/sec\text{Peak Crawl Rate} = 386 \times 3 \approx \mathbf{1,200\text{ pages/sec}}
  • Average Page Payload: 500Β KB500\text{ KB} (HTML + metadata).
  • Peak Ingress Network Bandwidth: Bandwidth=1,200Β pages/secΓ—500Β KB=600Β MB/secβ‰ˆ4.8Β Gbps\text{Bandwidth} = 1,200\text{ pages/sec} \times 500\text{ KB} = 600\text{ MB/sec} \approx \mathbf{4.8\text{ Gbps}}

Storage Footprint (Annual Accumulation)

  • Monthly Raw Storage: 109Β pagesΓ—500Β KB=500Β TB/month10^9\text{ pages} \times 500\text{ KB} = \mathbf{500\text{ TB/month}}
  • Annual Storage Footprint (Compressed Zstandard): AnnualΒ Storage=500Β TB/monthΓ—12Β monthsΓ—0.35Β compressionβ‰ˆ2.1Β PB/year\text{Annual Storage} = 500\text{ TB/month} \times 12\text{ months} \times 0.35\text{ compression} \approx \mathbf{2.1\text{ PB/year}}

Memory Sizing for URL Deduplication (Bloom Filter)

  • Tracking 5 Billion discovered URLs with a false positive rate p=0.001p = 0.001 (0.1%0.1\%): m=βˆ’nln⁑p(ln⁑2)2=βˆ’5Γ—109Γ—ln⁑(0.001)(0.6931)2β‰ˆ71.9Γ—109Β bitsβ‰ˆ8.98Β GBΒ RAMm = -\frac{n \ln p}{(\ln 2)^2} = -\frac{5 \times 10^9 \times \ln(0.001)}{(0.6931)^2} \approx 71.9 \times 10^9\text{ bits} \approx \mathbf{8.98\text{ GB RAM}} A modest easily hosts this in memory.

3. High-Level Architecture & AWS Component Mapping

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

4. URL Frontier Architecture (The Mercator Model)

To solve the dual challenges of Priority (crawling high-quality pages first) and Politeness (never overloading a single target web server), the crawler implements the Mercator Two-Tier Queue System:

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Politeness Heap Algorithm

  1. Each host queue maintains a state record: (hostname, last_access_timestamp, crawl_delay_ms).
  2. When a worker requests a URL, the coordinator inspects the Min-Heap.
  3. If Tnowβ‰₯next_fetch_timeT_{\text{now}} \ge \text{next\_fetch\_time}, the worker pops the next URL for that host, fetches the page, and reschedules the host in the heap for Tnow+crawl_delay_msT_{\text{now}} + \text{crawl\_delay\_ms} (minimum 1,000ms).
  4. This mathematically guarantees that no single web server ever receives concurrent or rapid-fire hits.

5. Storage Engine & Near-Duplicate SimHash Algorithms

1. 64-Bit SimHash Near-Duplicate Detection Algorithm

To prevent storing millions of mirror pages or template variations:

  1. Tokenize HTML body text into word shingles (e.g. 3-word n-grams).
  2. Compute 64-bit cryptographic hash for each shingle.
  3. Initialize a 64-element weight vector V=[0,0,…,0]V = [0, 0, \dots, 0].
  4. For each shingle hash, add +1+1 to V[i]V[i] if bit i=1i=1, else βˆ’1-1.
  5. Form the final 64-bit fingerprint: bit i=1i=1 if V[i]>0V[i] > 0, else 00.
  6. Hamming Distance Match: If HammingDistance(SimHashA,SimHashB)≀3\text{HammingDistance}(\text{SimHash}_A, \text{SimHash}_B) \le 3, the pages are near-duplicates; the crawler drops the redundant payload and only records canonical metadata.

2. DynamoDB Crawl State Schema (CrawlStateTable)

() ()AttributesDescription
HOST#<hostname>ROBOTSdisallow_rules (LIST), crawl_delay_ms (NUM), cached_at ( 24h)Cached robots.txt policies
URL#<sha256(url)>METADATAurl_raw, simhash_64, http_status, s3_uri, crawled_atVisited URL audit record

Part 2: Production Deep-Dive Locked1 Coin = 24 Hours

Unlock Complete Architecture & Production Runbooks

Your Balance:40 Coins

You have explored the free architectural preview (~48%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
6. Detailed Request Flow & Crawl Worker Lifecycle
7. Web Crawler Architecture Trade-Off Matrix
8. Failure Modes, Resiliency & Critical Edge Cases
9. Production Pitfalls & Anti-Patterns (The "Gotchas")
10. Production Runbook & Observability Guide
11. Interview Strategy & System Design Rubric
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure