AlgoViz

Design a URL crawler

hard 60 min

Start from a few addresses, download pages, find links, and repeat a billion times a month.

How to approach it

What this question tests, where it gets hard, and how to spend the time.

Read the question

What this problem tests

  • Can you find the real limit?

    Bandwidth and CPU are small. Hosts are the scarce thing.

  • Can you design a queue?

    Two orders at once: by value and by host.

  • Can you say about the same?

    Huge sets, near copies, and an error rate you accept on purpose.

  • Can you expect trouble?

    Traps, slow servers, bad data, and sites that say no.

Think

Five questions before you draw

Ask yourselfHere
Who does what?Operators set seeds and limits; fetchers visit; parsers read; the index team takes pages
What must never go wrong?Flooding a site, or ignoring its rules
What is the hardest thing?Choosing the next URL under two opposing rules
What breaks first as it grows?The single queue, then the set of seen URLs
What am I giving up?Completeness: some pages are skipped, all copies are a little old

Spend the 45 minutes

MinutesDoLeave withSkip
0 to 5Purpose, pages a month, politeness, freshnessHTML only, 1B a monthRanking
5 to 10Pages/s, hosts, seen set, bytes"Hosts are the limit"CPU to the last core
10 to 15Messages, URL recordA key and an owner for each URLAdmin endpoints in full
15 to 25One process, then growFrontier split by hostProduct names
25 to 40Frontier, then seen set or recrawlChoices with costsSimHash arithmetic, unless asked
40 to 45Traps, failures, recapA clear last sentenceNew features

Lines you can open with

  1. 1

    Start

    "Is it for search, an archive, or one site? I will assume search, HTML only, and that being polite is a hard rule."

  2. 2

    Park something

    "Rendering JavaScript is a side pool with its own budget. I will return to it if you like."

  3. 3

    When stuck

    "Which machine knows when this host may be visited next?"

  4. 4

    Close

    "One owner for each host gives politeness, a filter gives memory, a schedule gives freshness. Budgets protect us from the web."

Recognise

Patterns inside this problem

PatternThe signalWhere it lands
Single ownerA rule must hold across machinesPoliteness
Two-level queueTwo orders at onceFrontier
Approximate setToo many members, small harmSeen URLs
LeaseWorkers may vanishHosts in flight
Learned scheduleItems change at different ratesRecrawl
BudgetInput has no endPages for each host

Do

  • Clarify scale, politeness and freshness first
  • Say that hosts are the limit
  • Spend most time on the frontier
  • Name the error you accept

Traps

  • A global queue with many workers
  • A shared rate counter asked on every fetch
  • Treating robots.txt as optional
  • A table of ten billion rows scanned to find what is due