CodingNodes Space play · ←→ step · R restart

The problem

A web crawler — a spider or robot — walks the web for you. It starts from a handful of pages, follows the links on them to find more pages, and hands the content it collects to an index. Search engines, archives, and link-checkers all run some version of this loop.

The twist is that the input is untrusted and nearly infinite. A single page can link to millions of pages, most of them wrong, duplicated, or worse, so the whole design is about deciding which pages to fetch, how many to hold, and in what order.

Today you will build one: scope the job, keep a frontier of URLs to visit, pick a traversal order, download and deduplicate content, and pace the crawler so it is fast but polite.

Requirements

Functional — what it must do

  • Starting from a set of seed URLs, discover and fetch new pages by following the links found in the pages already fetched.
  • Keep an ever-growing frontier of candidate URLs and fetch them in a sensible order that reaches important pages early.
  • Never fetch the same URL twice, and skip URLs that are not part of the site(s) we are indexing.
  • Extract the page's links and its text so the index can store them, and record what each page linked out to.

Non-functional — how well it must do it

  • Coverage: reach a fixed fraction of the target sites' pages in a single full crawl, then keep up with what changes between crawls.
  • Politeness: cap the request rate per domain, honor a site's crawl-delay and robots.txt, and never hammer one origin.
  • Efficiency: spend the budget on the most valuable pages first, so an interrupted crawl still returns a useful index.
  • Robustness: tolerate dead links, slow servers, encoding quirks, and redirects without losing the thread.

Scale — how much it must take

  • A crawl of roughly one billion target URLs, pulling down about 2,000 pages per second at peak across the crawler fleet.

Assumptions — the numbers this design is sized for

A rate limit means nothing without a scale. These are the figures every later part relies on: how much traffic arrives, how much work the limiter has to do per second, and how much latency and memory it may spend doing it.

Target universe
≈ 1,000,000,000 URLs
The candidate URLs we must consider across the target domains. The frontier must hold a working slice of them.
Fetch rate
2,000 pages/s
Peak across the fleet. At ~10 KB of text per page that is about 20 MB/s of new content.
Full-crawl budget
≈ 1 week
1 billion URLs at an average of 1 request per 2 s would be far too slow; the fleet parallelizes to finish in days.
Dedupe memory
tens of GB
A fingerprint per seen URL. A Bloom filter over a billion URLs is a few GB with a small false-positive rate.
Links per page
≈ 15
Each fetched page yields ~15 new candidate URLs, so the frontier grows about 30 million per second at peak — it must be filtered hard.
Politeness cap
≤ 1 req/s / domain
Per origin. One abusive site is throttled to one request a second regardless of how many links it offers.
Change rate
≈ 5% / crawl
A few percent of pages change between full crawls; incremental crawls chase those, not the whole universe.
Storage per page
≈ 10 KB text
The extracted text plus a few links. The full rendered HTML is kept on object storage, not in the hot path.

Takeaways

Part 1

Scope: what do we crawl

A crawler can index the whole web, a slice of it, or just track one site for changes. That choice fixes the frontier's size and its ordering goal.

  1. 1
    Three different jobs

    A search-engine crawler wants maximum coverage of as many domains as possible. A link-checker wants to walk one site's pages and report the broken ones. A change-detection crawler wants to re-fetch only what moved since last time. The plumbing is shared; the frontier size and the ordering goal differ.

  2. 2
    We scope to coverage

    We design the coverage crawler: start from seeds, follow links, and build an index of as many reachable pages as the budget allows, prioritizing the important ones. That is the hard case — if it works for a billion URLs, the other two are just narrower frontiers with a simpler order.

Part 2

The URL frontier

The heart of a crawler is a queue of URLs not yet fetched. It grows with every page you read and shrinks with every fetch — and it must stay bounded and deduplicated.

  1. 1
    The frontier queue

    Keep a queue of candidate URLs. Each time we fetch a page we push the links we find on it into the queue, and each time we fetch we pop one off. That is the whole loop. The danger is that the queue grows about 15× faster than we drain it, so we must decide what to keep.

  2. 2
    BFS: breadth first

    Fetched in the order added, the frontier behaves like a breadth-first search: we visit near pages before far ones, which is exactly what we want — a homepage's immediate neighbors are usually more useful than a ten-click-away page. The queue naturally keeps the important, reachable pages front-loaded.

  3. 3
    Why not DFS

    A depth-first walk would dive one link-chain all the way to a dead end before coming back. It can use little memory, but it reaches deep, often unimportant pages first and leaves the useful near ones waiting. For a coverage crawl that spends the budget on the wrong pages, so breadth-first wins.

Part 3

Never fetch twice

The web is full of the same page at many URLs, and links repeat constantly. A crawler that does not deduplicate wastes most of its budget.

  1. 1
    The duplicate problem

    Two of three problems a crawler faces are about duplicates. The same URL shows up on many pages, and the same content lives at slightly different URLs — with or without a trailing slash, with a session token, over http and https. Fetching each one is wasted budget and a bloated index.

  2. 2
    Dedupe by fingerprint

    Before adding a URL to the frontier, compute a cheap fingerprint and check it against the set of URLs we have already seen. If it is already there, drop it. This is the single most important filter — it is what keeps the frontier from exploding.

  3. 3
    A Bloom filter does it in gigabytes

    Holding a billion seen URLs as full strings would take hundreds of gigabytes. A Bloom filter does the same job in a few gigabytes with a tiny false-positive rate — the occasional duplicate we fetch twice is a far cheaper failure than the memory of holding every URL. That is the standard trick at search scale.

  4. 4
    Dedupe by content too

    Even distinct URLs can hold the same content — a syndicated article on a hundred sites. We fingerprint the page body, not just its URL, and keep only one copy in the index. A random polynomial fingerprint (the Rabin trick) makes this a fast, order-independent comparison.

Part 4

Fetching and extracting

Once a URL is chosen, the downloader fetches it, extracts the text and the links, and hands both to the index — all behind a politeness cap.

  1. 1
    The fetcher

    A pool of downloaders pulls a URL over HTTP, applies a timeout, and follows a bounded number of redirects. The response is handed to an extractor that strips the markup and returns the readable text plus the list of outbound links. Everything runs behind a per-domain rate cap so no single site is hammered.

  2. 2
    Robust to the messy web

    Real pages misbehave: a server hangs, a page is gzipped, an encoding is declared wrong, a redirect loops. The downloader must treat each of these as a per-URL failure, not a crash — log it, move on, and keep the loop turning. One slow site must never stall the whole crawl.

  3. 3
    Politeness is enforced, not hoped for

    The rate cap is applied at the point where a fetch leaves the crawler: a token is reserved for the target domain, and if that domain is over budget the URL is queued to try again later. That is the difference between a crawler that is useful and one that gets a site's servers blocked.

Part 5

Crawl the important pages first

With a finite budget, the order we fetch matters more than the rate we fetch. PageRank-style scoring puts the valuable pages at the front of the frontier.

  1. 1
    Not all URLs are equal

    A homepage is worth far more than a photo deep in a blog's archive. If the crawl is interrupted halfway, we want the index to contain the important pages even if it is missing the long tail. So the frontier is not a plain FIFO queue — it is a priority queue.

  2. 2
    A score: link-based importance

    The classic signal is who links to a page and how. A page that many important pages link to is probably important in its own right — the same idea behind PageRank. We use that score to order the frontier, so the crawl walks outward from the hubs first.

  3. 3
    Freshness beats age

    For a live index, a page that changes often deserves re-crawling sooner than one that is static. We blend the importance score with a recency and change-rate signal so the frontier stays skewed toward the pages that are both valuable and likely to have moved since the last crawl.

Part 6

Avoid the traps

A crawler can be derailed by content designed to waste it: infinite link loops, hidden text, and pages that look like targets but are not.

  1. 1
    The infinite loop

    A page that links to a page that links back, forever, will spin a naive crawler in circles. The seen-set stops the URL loop, but a whole domain of mutually-linked pages can still drain the budget. We cap how deep we follow and how many pages we pull from any single origin in one crawl.

  2. 2
    Hidden and doorway content

    Some pages stuff text in a color that matches the background, or are pure link farms built to game rankings. The extractor must decide what is real content and what is decoration — dropping text that is invisible, off-screen, or only in a hidden element keeps the index clean.

  3. 3
    Stay in scope

    A link is a candidate, not a command. We only follow URLs that belong to the domains we are indexing, and we drop dynamic URLs that would generate a new page per click — a search box's result links, a 'next page' chain, a login wall. The frontier stays a map of the target sites, not the whole corner of the web.

★ Finale

End to end

One page in, a frontier out: we fetch a page, extract its text and links, deduplicate, score, and enqueue the next batch — then repeat until the budget runs out.

  1. 1
    The whole crawler

    Everything in one diagram. Seeds enter the frontier. A downloader pool pulls URLs in priority order, an extractor turns each page into text and links, a seen-set stops the duplicates, and a scorer decides what goes back to the front of the queue. The index is written as each page lands.

  2. 2
    A page comes in

    The downloader pulls the next highest-priority URL. The page arrives; the extractor strips it to readable text and pulls out fifteen outbound links. The text is written to the index. That is the useful half done — the page is captured.

  3. 3
    The links are filtered

    Each of the fifteen links is fingerprinted and checked against the seen set. Eight are new and are kept; seven are URLs we already fetched, so they are dropped. The dedupe filter just cut the frontier's growth by nearly half on this page.

  4. 4
    They are scored and enqueued

    The eight new URLs get an importance score from their link context and a change-rate estimate, then are inserted into the priority frontier. The highest-scoring ones sit at the front, so the next fetch reaches a valuable page — the crawl keeps spending its budget where it matters.

  5. 5
    …and it repeats

    Fetch, extract, dedupe, score, enqueue — over and over, two thousand times a second across the fleet, bounded by the per-domain politeness cap. A week later the index holds a billion pages, skewed toward the important and the current. That is a web crawler.

🌐 In the wild

In the wild

The same frontier-and-dedupe loop is what runs real search crawlers. Here is where each piece shows up in the field.

  1. 1
    These crawlers run the web

    Everything you just built is a production search crawler. The priority frontier, the seen-set, the politeness cap, and the importance scoring are the same pieces that walk the web for the big search engines. Let's match the diagram to the names.

  2. 2
    Googlebot: the reference crawler

    Googlebot is the crawler behind Google search, and it is the canonical example of everything in this chapter: a huge frontier, per-domain politeness, and an importance-driven order that reaches the most useful pages early. It is also the one that set the expectations for how polite a crawler should be.

  3. 3
    PageRank: the ordering signal

    The 'crawl the important pages first' idea is literally PageRank: the 1998 Stanford paper that scores a page by who links to it and how important they are. It turned the crawler's ordering from 'whatever we hit first' into 'what the web points at most', and it is still the backbone of link-based importance today.

  4. 4
    Bloom filters: the seen-set

    The gigabyte-scale seen-set you designed is exactly what a Bloom filter is for — the 1970 data structure that answers 'have I seen this?' in a few gigabytes with a small, known false-positive rate. At crawler scale it is the difference between a seen-set that fits in memory and one that does not.

  5. 5
    IRLbot: crawling at billions of pages

    The IRLbot project scaled crawling to six billion pages and beyond — a direct, published account of the exact problems you just solved: frontier management, politeness, and deduplication at a scale where memory and order make or break the run. Your design, with the numbers turned up, is what those systems describe.