Design a web crawler
Design a crawler that fetches a large portion of the web, stores the pages for later processing, and keeps them reasonably fresh. It must not overload the sites it visits and must not fetch the same content repeatedly.
About this problem
“Design a web crawler” is a core-level problem in the crawling and ingestion family. The work is unbounded, the sources are hostile or fragile, and you are a guest on someone else's machine.
The key challenge: Nobody is waiting for any single page. This group has the most slack in the app, and most good decisions here come from spending it.
Time budgets: Per page: unlimited. Full recrawl: days. Freshness for news: minutes.
The worked solution for Web crawler goes through why those budgets shape the design, stage by stage.
Before you start
You will work this in five timed stages. Here is what each one asks you to think about. None of it is the answer; the answers unlock in the workspace below once you have written your own.
- Stage 1 · Requirements · 5 min
- What is this crawler for? Search, archiving and price monitoring are different systems.
- How much of the web, and how fresh? Both are dials, not facts.
- What are you allowed to fetch?
- Stage 2 · Actors and lifecycle · 6 min
- The websites are actors, and they have opinions about you.
- What silent decisions does the crawler make about each URL?
- A URL can fail in about six interesting ways. What are they?
- Stage 3 · Numbers · 6 min
- Work backwards from a target: how many pages in how many days?
- What does a page cost to store, compressed?
- How much memory does it take just to remember which URLs you have seen?
- Stage 4 · High-level design · 12 min
- How does the queue enforce a delay per domain rather than globally?
- Where does the seen-set live, and who can ask it?
- What is stored, and in what shape, for the next system to use?
- Stage 5 · Deep dive and tradeoffs · 14 min
- What happens when one domain has 500 million pages?
- How do you decide what to recrawl when you cannot recrawl everything?
- What stops a crawler trap from consuming the entire fleet?
Work it through
Five stages, gated. You write your answer for each stage before its model answer unlocks. That is the core of the method.
Done all five? The diagrams, numbers, trade-offs and follow-ups for this problem are on the worked solution page, to check your own design against.
How it is really built
Write your own answer first. Then read how teams who run this at scale describe it. Their constraints were real, and the write-ups often say what their choices cost.
- Percolator (Google, OSDI 2010) ↗How Google moved its index from batch rebuilds to incremental updates as pages are recrawled. Useful for the "what happens after the fetch" follow-up.