Design a web crawler by defining a prioritized URL frontier, a fetcher with strict politeness and timeout rules, a parser that extracts new links and content, a deduplication layer, and durable storage for both the frontier and what you've already seen—then wrap the whole thing in controls that keep it within a site's rules and your own resource limits. The architecture is less about any single clever algorithm than about how those components interact under load, because a crawler that works on ten pages will usually collapse on ten million unless you've designed for the failure modes from the start.

The question can be read two ways, and the distinction matters. A focused crawler (sometimes called a topical crawler) fetches selectively—search-engine indexing, price monitoring, research sampling—and spends most of its design effort on prioritization and politeness. An exhaustive crawler tries to capture an entire site or subdomain and spends its effort on completeness and resumability. Most real systems are somewhere in between. This article covers the general design, noting where the two goals diverge.

Start With Scope and Seed Selection

Before writing code, decide what the crawler is allowed to touch. Scope has four dimensions:

Host scope—one site, a set of domains, or the open web. Path scope—everything under a prefix, or filtered by URL patterns. Content scope—HTML only, or also PDFs, images, APIs, JavaScript-rendered pages. Time scope—a one-time snapshot or continuous recrawling to track changes.

Seed URLs follow from that. Good seeds are stable entry points: sitemaps, category indexes, and known hub pages. A crawler seeded only from a homepage and left to follow links will miss pages that aren't linked, which is why sitemap ingestion is standard practice for site-level crawls. For a focused crawler, seeds should be representative of the target topic, because early fetch decisions shape everything the crawler sees later.

Scope also determines your stopping rule. Open-web crawlers stop on a budget (pages, time, bytes); site crawlers stop when the frontier empties or a coverage threshold is met. Decide this early—it changes how you build deduplication and prioritization.

The Core Loop, Component by Component

Every crawler, from a hundred-line script to a distributed system, runs the same loop: pick a URL → fetch it → parse it → extract and enqueue new URLs → store the result → repeat. The engineering is in making each step robust.

The URL frontier

The frontier is a priority queue of URLs waiting to be fetched. Two design decisions dominate:

Ordering. A plain FIFO queue produces breadth-first crawling, which is a reasonable default because it finds important hub pages early. Production crawlers use a score: page importance (inbound links, proximity to seeds, topic similarity), freshness (how long since last fetch), and host fairness (don't let one large site monopolize the queue). The frontier is usually organized per-host, with a global scheduler that interleaves hosts so no single site is hammered.

Politeness state. Each host needs a record of the last request time and a minimum interval, so the scheduler can enforce delays. This is often implemented as separate per-host queues plus a "ready" set of hosts whose delay has elapsed.

The fetcher

The fetcher's job is to make HTTP requests and handle everything that goes wrong. Minimum requirements:

Timeouts on connect and read, short enough to avoid stalling the pipeline. Redirect handling with a cap (typically five to ten hops) to avoid loops. Retry with backoff for transient errors (timeouts, 5xx), but not for permanent ones (404, 403). Conditional requests—sending If-Modified-Since or If-None-Match so recrawls are cheap when nothing changed. A clear User-Agent identifying the crawler and a contact URL. This is both courteous and practical: site operators use it to whitelist or contact you.

Many crawlers use a headless browser for JavaScript-heavy sites, which multiplies cost by an order of magnitude or more. Treat rendering as an opt-in path triggered by heuristics (the HTML is thin, or known frameworks are detected), not the default.

The parser

The parser extracts two things: content (text, metadata, structured data) and links (new URLs to consider). It must be defensive—malformed HTML is the norm, not the exception—and it must resolve relative URLs against the page's base URL, honoring tags when present.

Link extraction is where most scope bugs appear. You need to normalize URLs before comparing them: lowercase the scheme and host, remove default ports, strip fragments, sort query parameters if order is semantically irrelevant, and decide how to handle trailing slashes. Two URLs that look different may be the same page, and two that look identical may differ by a parameter that changes content.

Deduplication

There are two distinct deduplication problems, and conflating them causes trouble.

URL deduplication prevents re-fetching the same address. A normalized-URL hash set, persisted to disk or a database, is sufficient. It must survive restarts, which is why an in-memory set alone is inadequate for anything long-running.

Content deduplication catches the same content served at different URLs—mirrors, tracking parameters, print versions, session IDs. The standard tool is a similarity hash: compute a fingerprint of the normalized text (SimHash or MinHash variants are common), and compare against stored fingerprints within a threshold. Exact hashing alone misses near-duplicates; similarity hashing alone lets through exact duplicates. Many systems use both layers.

A third, often-forgotten variant is trap avoidance: calendars with infinite "next month" links, session-ID loops, and faceted navigation that generates unbounded URL permutations. URL normalization handles some of these. For the rest, cap the number of URLs per host, cap path depth, and detect patterns of self-similar URLs.

Storage

You need two stores, and they have different access patterns. The frontier store needs durable, resumable queue semantics—a database table with status columns works and is far easier to operate than a bespoke queue. The content store is append-only: raw HTML, extracted text, metadata, fetch timestamps, and status codes. Keep the raw response alongside the parsed output, because parser bugs are common and re-fetching to fix them is expensive.

Politeness, robots.txt, and the Law

Politeness is not optional, and it has several layers.

robots.txt is the baseline convention. Fetch it per host, cache it with an expiry (it can change), and honor User-agent, Disallow, and Crawl-delay directives. Parse it carefully: implementation bugs in robots parsing are a common source of accidental violations. If the robots file returns an error, the conservative default is to treat the site as disallowed or to back off, not to proceed at full speed.

Rate limiting goes beyond robots.txt. A reasonable default is one request per second per host, adjusted by site size and response times; large sites may tolerate more, small sites less. Adaptive approaches that slow down on 429 or 503 responses are better than fixed rates, because they respect the server's own signals.

Identification and contactability: a descriptive User-Agent with a URL that explains the crawler and how to opt out is standard professional practice.

Legal and contractual constraints vary by jurisdiction and site. Terms of service, database rights, and copyright apply to what you fetch and how you use it. This is a genuine area of variation, so if you're crawling commercially, get advice for your jurisdiction rather than assuming a single global rule. The technical design (politeness, robots compliance, conservative rates) is the part you can settle yourself.

Prioritization: The Design Lever That Matters Most

For any crawl that can't fetch everything, prioritization determines quality. A practical scoring function combines:

Structural signals: distance from seeds, whether the URL sits in a sitemap, path patterns that indicate content versus navigation. Link signals: number of internal inbound links, anchor text relevance. Freshness: time since last fetch, and Last-Modified / sitemap timestamps. Topic signals for focused crawls: similarity of the page to a target profile, often computed from anchor text and the parent page's score.

The score feeds the frontier's ordering. Crucially, the score should be recomputed as evidence accumulates—a page that keeps appearing in links from high-value pages should rise. A simple two-tier scheme (high-priority queue and bulk queue) often beats a complex scoring model in practice, because it's easier to debug and to explain.

Scale-Out Architecture

Once a single machine can't keep up—or when you need resilience—the standard pattern separates concerns:

A URL frontend/scheduler that owns the frontier and distributes work. A fleet of fetchers that pull URLs, fetch, and push results to a queue. Parser/extractor workers that consume fetched pages and emit new URLs back to the scheduler. Shared stores for dedup state and content.

The hard problems at this scale are coordination (avoiding two fetchers hitting the same host simultaneously), state size (dedup sets grow into the billions of entries and need partitioned or approximate structures), and back-pressure (slow parsers shouldn't let the fetch queue grow without bound). Partitioning by host is the common answer: it makes per-host politeness and per-host rate limiting natural, because one worker owns a host's requests.

What to Instrument, and How to Test

A crawler without observability is a liability. Track:

Fetch success rate by status code, per host. Bytes fetched over time, and average page size. Frontier size (ready vs. waiting), and time-to-first-fetch per URL. Duplicate rates (URL and content), which reveal normalization gaps. Per-host request rates, to catch politeness bugs.

Test with a small, controlled site first—ideally one you run—so you can verify coverage completeness, redirect handling, robots compliance, and restart behavior without disturbing anyone else's servers. Then test resumability by killing the process mid-crawl: a well-designed crawler picks up where it stopped, and the frontier store is where that guarantee lives.

Common Design Mistakes

In-memory-only state. Anything that must survive a restart—frontier, dedup sets, robots cache—belongs in persistent storage.

Treating URL equality as string equality. Without normalization, dedup fails and crawlers re-fetch at scale.

Ignoring politeness under parallelism. Adding workers multiplies pressure on hosts unless rate limits are enforced per host, not globally.

Following every link. Link extraction without scope rules and trap detection produces unbounded frontiers.

No content dedup. Mirrors and parameter variants inflate storage and skew any analysis downstream.

A Reasonable Minimum Design

If you're building your first crawler, start with this: a persistent frontier table ordered by a simple score; a fetcher with timeouts, redirect caps, and retry-with-backoff; a defensive parser with URL normalization; a URL-hash dedup set and a content fingerprint store; per-host rate limiting with robots.txt compliance; structured logs; and a kill-and-resume test. That design won't handle a billion pages, but it will handle a real site correctly—and every scaling decision afterward (rendering, partitioning, distributed scheduling) is a variation on these same components rather than a replacement for them.