Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Distributed Web Crawler
& Indexing Frontier (Googlebot Scale).

Shard the Mercator URL Frontier by hash(host), pair with async DNS caching, RocksDB/Bloom URL deduplication, 64-bit SimHash content dedup, and URL-depth/pattern trap guards.
Start the journey7 stages· Last modified Nov 22, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When traffic spikes expose hidden coupling, consistent-hash by hostname (not full URL) so each host's politeness timer and `robots.txt` cache live on one shard.

TL;DR30-second simplified summary
▾

Crawling 10B pages/month (~4,000 pages/sec) across a distributed fetcher fleet breaks down quickly if URLs are sharded by hash(url)—because 50 workers would hit example.com simultaneously.

Sharding the Mercator Frontier by hash(hostname) guarantees every domain's Back Queue, robots.txt cache (24h TTL), and politeness timer reside on a single owner shard. Fetchers use non-blocking async DNS resolvers (avoiding glibc getaddrinfo thread blocking) and stream parsed pages through a 64-bit SimHash (Hamming distance <= 3) near-duplicate detector before indexing.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Distributed Web Crawler & Mercator URL Frontier
The Mercator URL Frontier separates crawl priority (Front Queues) from per-host politeness (Back Queues) so high-priority domains are crawled fast without DDoSing any single origin server.
Consistent Hashing & Virtual Nodes
Consistent hashing assigns data keys to servers in a way that limits how many keys move when servers are added or removed. This helps avoid widespread cache misses and sudden load on databases.
Bloom Filters, Counting Bloom & Cuckoo Filters
Bloom filters answer set membership in O(k) bit probes using ~10 bits per key at a 1% false-positive rate with zero false negatives, while Cuckoo filters store compact fingerprints in 2-choice hash buckets to support safe item deletion and better CPU cache loc...
Full walkthrough · 7 stages
01
STAGE 01 · CORE INTUITIONfoundation

Scale Envelope & Latency Budget.

Why this matters: Size 10B-URL/day crawl throughput, Mercator politeness queues, and Bloom-filter deduplication memory.

Think of Scale Envelope & Latency Budget as the intuition layer for Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale): Size 10B-URL/day crawl throughput, Mercator politeness queues, and Bloom-filter deduplication memory.

Design a distributed web crawler indexing 10B web pages/month (~4,000 pages/sec sustained, 10K+ peak) with strict per-host politeness, robots.txt compliance, < 2% duplicate content storage, and resilience against infinite-URL crawler traps.

STAGE 01 · CORE INTUITION

Scale Envelope & Latency Budget

10B Pages / DayCrawl ThroughputMercator FrontierPolite SchedulerPartitioned BloomURL DedupAsync DNS + FetchPolite Fetchdedups via

1.Throughput Target: 10B pages/day (~115K pages/sec) across distributed fetcher pods without overwhelming origin servers.

2.Mercator Politeness: Separate priority Front Queues from per-host Back Queues so 1 host never receives concurrent bursts.

3.Memory Bound: Partitioned Bloom filters deduplicate 10B seen URLs in ~12 GB RAM instead of 640 GB.

Mercator priority/politeness queues and partitioned Bloom filters sustain 10B pages/day within bounded RAM.

02
STAGE 02 · CORE MECHANICSfoundation

Core Architecture & Data Flow.

Why this matters: Assemble the primary data path and storage layout.

Think of Core Architecture & Data Flow as the intuition layer for Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale): Assemble the primary data path and storage layout.

Sharding the Mercator Frontier by hash(hostname) guarantees every domain's Back Queue, robots.txt cache (24h TTL), and politeness timer reside on a single owner shard. Fetchers use non-blocking async DNS resolvers (avoiding glibc getaddrinfo thread blocking) and stream parsed pages through a 64-bit SimHash (Hamming distance <= 3) near-duplicate detector before indexing.

Lifecycle & Failure Recovery

Core Architecture & Data Flow

index scanfsync WALdeadlock / skewTx Active(Snapshot)Row Lock HeldWAL FlushedSerializationRetry
Engineering Decision Framework
Problem
How to implement Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When traffic spikes expose hidden coupling, consistent-hash by hostname (not full URL) so each host's politeness timer and robots.txt cache live on one shard.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · SAFE IMPLEMENTATIONintermediate

Crawler Trap & Robots Guard.

Why this matters: Reject infinite URL traps and disallowed paths before enqueueing discovered links.

from urllib.parse import urlparse

def is_safe_to_enqueue(url: str, max_depth: int = 8, max_len: int = 512) -> bool:
    if not url or len(url) > max_len:
        return False
    parsed = urlparse(url)
    if parsed.scheme not in ('http', 'https') or not parsed.netloc:
        return False
    segments = [s for s in parsed.path.split('/') if s]
    if len(segments) > max_depth or len(set(segments)) < len(segments) - 2:
        return False  # Reject repeating path-loop traps (/a/b/a/b/a/b)
    return True
04
STAGE 04 · SCALING & TRADE-OFFSintermediate

Sharding & Hot-Spot Mitigation.

Why this matters: Prevent single-partition bottlenecks at peak load.

Think of Sharding & Hot-Spot Mitigation as the intuition layer for Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale): Prevent single-partition bottlenecks at peak load.

Partition state deterministically and apply bounded-load or sub-bucket sharding for hot keys.

Request & State Flow

Sharding & Hot-Spot Mitigation

Client TxPlanner / Lock MgrWAL / MemTableHeap / SSTable1. Acquire snapshot / index plan2. Append redo record + fsync WAL3. Flush dirty pages / compactSSTables4. Commit & release row locks
05
STAGE 05 · FAULT ISOLATIONadvanced

Failure Modes & Graceful Degradation.

Why this matters: Keep critical paths healthy during partial outages.

Think of Failure Modes & Graceful Degradation as the intuition layer for Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale): Keep critical paths healthy during partial outages.

Apply circuit breakers, fallback caches, and dead-letter quarantine queues.

Component Topology

Failure Modes & Graceful Degradation

Client TxingressQuery PlannercomputeWAL BufferstorageStorage PagescontrolSQL queryappend redocheckpoint flush
06
STAGE 06 · RECOVERY & CONSISTENCYadvanced

Consistency, Idempotency & Recovery.

Why this matters: Guarantee correctness across retries and node crashes.

Think of Consistency, Idempotency & Recovery as the intuition layer for Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale): Guarantee correctness across retries and node crashes.

Enforce atomic state transitions, fencing/idempotency keys, and fast snapshot recovery.

07
STAGE 07 · OBSERVABILITY & GUARDRAILSadvanced

Telemetry, Circuit Breakers & Failure Modes.

Why this matters: Monitor 429/503 origin pushback, DNS cache hit ratios, crawler-trap drops, and Back-Queue starvation.

Think of Telemetry, Circuit Breakers & Failure Modes as the intuition layer for Design a Distributed Web Crawler & Indexing Frontier (Googlebot Scale): Monitor 429/503 origin pushback, DNS cache hit ratios, crawler-trap drops, and Back-Queue starvation.

Track p99 latency, retry/conflict ratios, and saturation metrics; fail fast with bounded retries and circuit breakers whenever invariants degrade.

STAGE 07 · OBSERVABILITY & GUARDRAILS

Telemetry, Circuit Breakers & Failure Modes

429 / 503 OriginRatePoliteness SignalDNS Cache Hit RatioResolver KPITrap / Depth DropsTrap GuardBack-QueueStarvationQueue Healthpairs with

1.Adaptive Backoff: Double per-host crawl delay automatically whenever an ASN exceeds 2% 429 responses.

2.Trap Telemetry: Track dropped repeating-segment URLs to catch infinite calendar/session crawler traps.

3.DNS Health: Alert if async Unbound/c-ares DNS cache hit ratio drops below 95%.

Tracking 429 rates, DNS cache hits, and trap-drop counters keeps 10B-page crawls fast and polite.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why must the crawler frontier shard by `hash(hostname)` rather than `hash(full_url)`?

Recommended Learning Flow