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.
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.
Scale Envelope & Latency Budget
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.
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.
Core Architecture & Data Flow
- 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.txtcache live on one shard. - Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
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?
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 TrueSharding & 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.
Sharding & Hot-Spot Mitigation
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.
Failure Modes & Graceful Degradation
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.
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.
Telemetry, Circuit Breakers & Failure Modes
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: Make the trade-off yourself.
Why must the crawler frontier shard by `hash(hostname)` rather than `hash(full_url)`?