Skip to main content

Module 6: Case Studies

Web Crawler

Design a Google-like web crawler — URL frontier, politeness, robots.txt, distributed workers, dedup, and content storage.

A crawler discovers URLs, fetches pages politely, extracts links, and feeds downstream indexers. Interviews reward a clear loop plus operational details — DNS, politeness, and dedup — not just “many scrapers.”

What you will learn

  • Clarify coverage vs freshness goals before drawing boxes
  • Model the crawl loop and BFS/priority URL frontier
  • Enforce politeness, robots.txt, and per-host rate limits
  • Distribute workers with sharded queues and URL dedup
  • Store content/metadata and plan revisits without melting sites
A loop from the URL frontier to fetch, parse, stored content, and new URLs returning to the frontier.
Seed the frontier, fetch politely, store the page, and enqueue only new links.

Clarify goals

  • A crawler can optimize for breadth, freshness, or vertical depth. Ask which one matters.
  • Coverage — discover as much of the web (or domain set) as possible
  • Freshness — re-crawl important pages often
  • Scope — whole web, one vertical, or allowlisted domains
  • Outputs — raw HTML, extracted text, links graph for the indexer
  • Constraints — politeness, legal/ToS, crawl budget (pages/day)

Core crawl loop

  • Everything else hangs off this loop. Draw it first.
  • Seed URLs enter the frontier
  • Worker dequeues a URL → DNS → fetch → check status
  • Parse HTML → extract canonical URL, links, metadata
  • Emit content to storage; enqueue new unseen links to the frontier
  • Update crawl metadata (last fetched, checksum, next revisit)

URL frontier

  • The frontier is the crawler’s to-do list. Priority beats naive FIFO at scale.
  • BFS-style exploration avoids drowning in one deep site early
  • Priority scores: PageRank-like importance, change frequency, seed weight
  • Per-host queues so politeness can be enforced locally
  • Back-pressure when the frontier grows faster than fetch capacity
  • Persist the frontier — memory-only queues die on restart

URL normalization & dedup

  • Without dedup, you refetch the same page forever under different spellings.
  • Normalize scheme/host/path, strip fragments, sort query params carefully
  • Canonical tags and redirects should update the “seen” identity
  • Bloom filter for “probably seen” at huge scale (allow rare false positives)
  • Exact key-value / DB for confirmed URL metadata when needed
  • Content fingerprint (hash) detects duplicate bodies across URLs

Politeness & robots.txt

  • A production crawler is a good network citizen — interviews expect this.
  • Fetch and cache robots.txt per host; respect Disallow and crawl-delay
  • Per-host rate limits — never stampede one origin
  • Host affinity: same worker/queue handles a host to honor spacing
  • Identify via a clear User-Agent; provide an opt-out path
  • Backoff on 429/503; honor Retry-After when present

Fetching & parsing

  • The fetcher is where timeouts, encodings, and HTML mess become real.
  • HTTP client pools with strict timeouts and size caps
  • Follow redirects with a max hop count; detect redirect loops
  • Handle encodings, compressed responses, and non-HTML types
  • Extract links from anchors; optionally sitemaps for discovery
  • Sanitize/skip junk: infinite calendars, session-id URL traps

Distributed workers

  • One machine cannot crawl the web. Partition work without breaking politeness.
  • Sharded frontier queues (by host hash) → workers pull tasks
  • Fetcher fleet scales horizontally with crawl budget
  • DNS caching/resolvers in front — crawlers die on DNS bottlenecks
  • Retries with backoff for transient network failures
  • Isolate parser/indexer stages via queues so fetch stays busy

Storage & revisit policy

  • You need the page now and a plan to come back later.
  • Content store: object storage for raw HTML/warc; DB for metadata
  • Metadata: url, status, last_crawled, checksum, next_fetch_at, host
  • Revisit important/changing pages more often; stable pages rarely
  • Conditional GETs (If-None-Match / If-Modified-Since) save bandwidth
  • Downstream indexer consumes new/changed documents asynchronously

Priority, freshness, and budgets

  • Crawl budget is finite. Spend it on the pages that matter.
  • Score URLs by importance × staleness risk
  • Recycle high-value hosts more frequently
  • Cap per-host share of global budget so one site cannot monopolize
  • Seed & sitemap boosts for known important entry points
  • Monitor coverage and age-of-index as product metrics

Failure modes & abuse traps

  • The web fights back with traps, spam, and Meltdown-sized frontiers.
  • Spider traps / infinite URL spaces — depth caps and path heuristics
  • Soft 404s and cloaking — quality filters before indexing
  • IP blocks — respect them; rotate carefully only within policy
  • Frontier explosion — dedup + prioritization + discard low-value links
  • Parser crashes — sandbox and isolate bad documents

Interview framing

  • Use this order in a crawler design round.
  • Goals: coverage vs freshness vs scope + crawl budget
  • Draw seed → frontier → fetch → parse → store → enqueue links
  • Add politeness, robots.txt, per-host queues
  • Add dedup (Bloom + metadata) and distributed sharding
  • Close with revisit policy and indexer handoff

Quick revision checklist

  • Ask about freshness vs coverage goals.
  • Mention legal/ToS and politeness briefly.
  • Prefer BFS/priority over DFS for coverage.
  • Call out robots.txt and per-host rate limits.
  • Highlight DNS caching and retries.
  • Keep indexing async from fetching.

FAQs

Why not DFS?

DFS can trap the crawler in deep thin branches; BFS/priority yields broader coverage sooner.

How do you avoid overloading a website?

Per-host queues, rate limits, crawl-delay from robots.txt, and backoff on 429/503. Politeness is a hard requirement.

How do you detect duplicate URLs?

Normalize URLs, then use a Bloom filter and/or exact store of seen URLs. Content hashes catch identical bodies under different URLs.

Where is crawled HTML stored?

Usually object storage for raw bytes plus a metadata DB for crawl status and next revisit time. Indexers read from that pipeline asynchronously.

How do you keep pages fresh?

A revisit scheduler scores importance and change likelihood, then re-enqueues URLs. Conditional GETs reduce bandwidth when content is unchanged.

BFS vs priority frontier?

BFS explores broadly by depth. A priority frontier also ranks by importance/freshness so limited crawl budget hits valuable pages first.

Practice

Learner’s Task

  • Practice out loud for 10–12 minutes as if designing a production crawler.
  1. State scope (web vs allowlist), coverage vs freshness goal, and a daily page budget.
  2. Draw the core loop and explain why the frontier is priority/BFS, not DFS.
  3. Add politeness: robots.txt, per-host rate limit, and host-affinity queues.
  4. Describe URL dedup (normalize + Bloom/KV) and where HTML/metadata are stored.
  5. Write a 4-sentence closing: loop, politeness, distribution/dedup, and revisit/indexer handoff.