LESSON 08 · Distributed operation

Partition and operate the crawl

Spread hosts across workers while keeping scheduling state and health visible.

SYSTEM VIEW

The crawl path

Diagram view
Shards—
Hosts moved—
Host rate—

Watch example.org get one scheduler as its owner, change owners when a shard joins, and stay polite through the handover.

  1. A shard is one scheduler’s slice of the hosts. The Host router hashes each host to one of 20 shards, and example.org lands on Scheduler A. One place now owns that host’s rate policy, however many workers fetch for it.

    Shards
    20
    example.org
    Scheduler A

    What changed

    • example.org → Scheduler A
    • One owner per host
  2. Fetch workers lease eligible URLs from Scheduler A, claiming each for a limited time, many at once. Only Scheduler A decides when example.org is eligible: here, once every 2 seconds, an example pace. Apache Nutch partitions fetch lists by host, domain or IP for the same reason.

    example.org
    1 request / 2 s
    Paced by
    Scheduler A only

    What changed

    • Workers lease URLs from A
    • example.org: 1 request every 2 s
  3. Scheduler B joins as the 21st shard. A consistent-hash ring moves about 5% of hosts to it, example.org among them; modulo hashing would move about 95%. The ring doesn’t fix hot hosts or stalled workers, and shards add failure modes: add one only when a scheduler’s memory or CPU runs out.

    Ring
    about 5% move
    Modulo
    about 95% move

    What changed

    • Scheduler B, the 21st shard
    • About 5% of hosts move
    • example.org now maps to B
  4. Scheduler A stops scheduling example.org and saves its next-eligible time with the ownership change: last fetch 12:00:00, so next eligible 12:00:02 (example times). Only then does Scheduler B start, and its first fetch waits until 12:00:02.

    Last fetch
    12:00:00
    Next eligible
    12:00:02

    What changed

    • A stops scheduling example.org
    • Saved: next eligible 12:00:02
    • B fetches at 12:00:02
  5. Replay the handover without the save. Scheduler A fetches example.org at 12:00:00 and stops, but Scheduler B never gets the next-eligible time. It treats the host as eligible now and fetches at 12:00:01: two fetches inside one 2-second window.

    Last fetch
    12:00:00
    Second fetch
    12:00:01

    What changed

    • No saved next-eligible time
    • Second fetch at 12:00:01
    • Two fetches in one 2 s window
  6. With the save back in place, Fetch workers store each fetched version and its metadata in the Page store under a stable key, then publish a durable event to Index events. A retried write lands on the same key, so storing twice does no harm.

    Store
    versions, stable keys
    Then
    a durable index event

    What changed

    • Page under a stable key
    • Durable index event
    • Saved handover: 1 per 2 s again
  7. More workers raise total fetches a second, but example.org still allows 1 per 2 s, so its queue in Scheduler B ages. Monitoring watches queue age by priority, change-detection lag and per-host request rates. These show the host falling behind before total QPS does.

    Fleet
    more fetches/s
    example.org
    still 1 per 2 s

    What changed

    • More fetch workers
    • example.org still 1 per 2 s
    • Its queue age rises

Space plays · ← → step · Home resets

THE IDEA

How it works

Partition host queues across scheduler shards so one host’s rate policy has a clear owner. A shard is one scheduler’s slice of the hosts. Multiple downloader workers can lease eligible URLs; rebalance shard ownership as capacity changes without allowing two owners to violate a host delay. A consistent-hash ring reduces movement: going from 20 to 21 shards moves about 5% of hosts, where simple modulo hashing moves about 95%. It does not solve hot hosts or stalled workers by itself. Apache Nutch partitions fetch lists by host, domain, or IP for the same reason. Replicate durable frontier state, checkpoint ownership transitions, and make storage writes idempotent.

Hand over a host in order: the old owner stops scheduling it and saves its next-eligible time, and only then does the new owner start. Skipping that save can fetch a host twice in one delay window. Shards also add failure modes, so stay on one scheduler until its memory or CPU actually runs out.

Separate document storage from the index handoff: store fetched versions and metadata under stable keys, then publish a durable indexing event or batch. Watch queue age by priority, eligible-host count, fetch success and error rates, robots denials, bytes, duplicate ratio, change-detection lag, and per-host request rates. These signals expose starvation, floods, traps, and stale output before aggregate QPS looks wrong.

DECISION POINT

Adding workers raises total QPS but one important host still falls behind. Why?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Partition by host to preserve rate ownership, then rebalance carefully.
  • Measure both crawl health and the freshness of downstream indexed content.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 2
RecallQUESTION 01

Why assign each host queue a clear scheduler owner?

Choose an answer. You’ll see the explanation once you get it right.

Design a retail price monitor

Apply the chapter's scheduling and politeness ideas to targeted rechecks, where each site's request budget decides what is possible.

The brief

A service tracks product prices across many online retailers, shows customers price history, and raises an event when a price changes. URLs come from customer watchlists and retailer sitemaps, so this is targeted rechecking rather than open link discovery. Some products need rechecks every 15 minutes and most need one a day. The crawler must respect robots.txt and each site's rate limits. Alert delivery, logging in to retailers, and purchasing are outside this exercise.

  • Track 50 million product URLs across 20,000 retail sites. The 100 largest sites hold 60% of those URLs.
  • 1 million priority products are rechecked every 15 minutes, and the other 49 million once a day. Add 10% to fetches for retries. Use decimal units and 86,400 seconds per day.
  • A product page averages 400 KB. 20% of fetches need a headless browser, at about 2 CPU-seconds per render. These are example figures to verify.
  • Store a 100-byte price observation per planned recheck for a year (retries add none), and raw HTML for 7 days.
  • The default budget is 1 request per second per site, lowered by robots.txt, 429, or 503 responses. An event for a priority product should fire within 20 minutes of a price change; treat this as a target to verify.

Reading a design isn’t the same as producing one under a clock. Try it timed: the requirement change stays hidden until partway through.

Loading your draft…

State your scope and assumptions. Estimate fleet fetches per second with retries, bandwidth, rendering capacity, and storage. Then work out one site's daily budget and compare it with a large site's URL count.

0 / 4,000 characters

Name the components and what each stores or does. Trace one priority product from becoming due, through robots and rate checks, to a stored price and a change event.

0 / 4,000 characters

Explain recovery from a crashed worker. Then handle a retailer redesign and a block page served with status 200, neither of which should create a false price. Say which site's budget is your bottleneck and how you would show it.

0 / 4,000 characters

Respond to the flash-sale change below. Show the per-site rate it implies, then say what you would build, what you would decline to build, and what you would tell the product team.

The requirement changesCustomers now want products in flash sales rechecked every minute for two hours. Assume 20,000 such products at a time, concentrated evenly on 5 retailers. Work out the per-site request rate this implies, decide what you would build, and say what you would tell the product team.

0 / 4,000 characters

Write an initial response in all four sections to unlock the checklist and two worked approaches.

Practice designs

0 of 2 checkpoints answered correctly to complete this lesson.