System Design · Interview breakdown · Free article
Design a Web Crawler
Fetch 4,000 pages a second without hurting a single site, fetch each page once, walk past traps, survive a crash, and keep the copies fresh. Built one step at a time, with experiments you can run.
A web crawler downloads web pages, finds the links in each one, and follows them to more pages. The frontier keeps a queue per site and hands a worker the next site whose turn has come, so no site gets two requests at once. Sites are split across machines by a hash of the host name, so one machine owns each site’s queue, its robots.txt rules and its seen URLs. An 8-byte fingerprint of every URL answers “seen before?” exactly. Each fetch is leased and marked done last, so a crash repeats work instead of losing it, and revisits go where they buy the most freshness.
Difficulty: Hard. Reported in interviews at Atlassian, ZoomInfo, Meta, Glean, Monzo. Also asked as Design a distributed web crawler, Design Googlebot, Design a search engine crawler, Design a crawler for LLM training data.
How do you design a web crawler like Googlebot?
A web crawler is a program that downloads web pages, finds the links on each one, and follows those links to more pages. Search engines run crawlers to know what to show you. Googlebot and Bingbot are the famous ones. Common Crawl runs one and gives away what it collects. Companies that train language models run them too. The hard part is doing this billions of times a month without harming the websites, and without wasting the work on pages that tell you nothing new.
- Discovered: Linked from 40,000 pages. The same URL arrives 40,000 times. It should be fetched once.
- Waiting its turn: 1 request at a time. A thousand workers are free. The site can take one request at a time.
- Fetched: 200 OK · 180 KB. robots.txt allows it, the address is public, and the reply is capped at 5 MB.
- Stored and parsed: 61 links found. A crash here must lose none of the 61 links.
- Revisited: Next visit: in 3 days. Some pages change hourly and some never. Revisits go where they help.
Picture the address https://news.example/sport/cup-final. The crawler meets it on the news site’s homepage, and again on 40,000 other pages that link to the match report. It fetches the page once. It waits for its turn, because news.example is also being asked for thousands of other pages. It stores the HTML, finds 61 links inside, and passes them on. Three days later it comes back to see whether the report has changed.
Interviewers like this problem because the first drawing is easy. It has a queue of URLs, workers that fetch them, a store for the pages and a set of URLs already seen. The rest of the round is about the ways that drawing hurts other people’s servers, wastes its budget, or quietly loses pages.
Here is the design in brief. The frontier keeps a separate queue of URLs for every site. A worker takes the next site whose turn has come, so no site ever gets two requests at once. Sites are split across machines by a hash of the host name, so each site’s queue, its robots.txt rules and its seen URLs all live on one machine. An 8-byte fingerprint of every URL tells a new link from a known one exactly. Each fetch is leased and marked done only after its page and links are safe, and revisits go where they buy the most freshness.
The rest of this page is about the moments that design has to survive.
Here is the first one. The crawl starts from one seed, the news homepage. It holds 300 links, all on news.example. A thousand workers take the first thousand URLs from one shared queue. Three hundred requests reach news.example in the same second. Its servers slow down, then answer with errors, and its operators block the crawler’s addresses.
Here is the second. A city events site has a calendar with a “next month” link on every page. Each month is a new URL, so the set of seen URLs never stops it. A week later the crawler has fetched 400 empty months of the year 2060 and nothing else from that site.
What is the interviewer testing?
Most candidates draw the loop in the first ten minutes. Seed URLs go into a queue, and workers fetch the pages. A parser pulls out the links, and a set of seen URLs keeps a page from being fetched twice. That drawing is right. A mid-level answer often stops there.
The interviewer then pushes on what the loop does at scale. One site gets a thousand requests at once. The seen set needs to hold 30 billion URLs. A calendar never ends. A machine dies with its queue in memory. A news page changes hourly while a blog post never changes. A senior answer handles politeness, deduplication and the crash. A staff answer also splits the frontier across machines by site, sizes the seen set, and spends a revisit budget where it helps.
Spend most of the deep-dive time on the frontier: politeness first, then splitting it across machines, then the seen set. How to run a round has the time plan for a 45 to 60 minute round and a 15-minute screen.
What should you ask before drawing anything?
Four questions change the design. Ask them in the first two minutes. If the interviewer leaves one open, say your assumption out loud.
- What is the crawl for?
- A search engine wants the text and links of every page. An archive wants every version of every file, images included. A model-training crawl wants lots of clean text, once. Assume a search engine: HTML pages, their text and their links. Images and video are out.
- How many pages, and how often?
- Crawling a university’s website is a laptop job. Crawling the web is not. Assume 10 billion page fetches a month, counting new pages and revisits.
- Does a page need JavaScript to show its content?
- Some pages arrive as an empty shell and fill in only after scripts run. Running a browser for every page costs far more than a plain fetch. Assume plain HTML for now, and treat rendering as a follow-up.
- One pass, or keep the copies fresh?
- A one-off crawl ends when the queue is empty. A search engine never ends: it keeps coming back. Assume a continuous crawl that revisits pages.
Functional requirements
1. Crawl from seeds; follow each page’s links 2. Obey robots.txt; never overload a site 3. Store each page’s HTML for the indexer 4. Skip URLs and pages already seen 5. Revisit pages; changed pages sooner out: ranking, JS rendering, logins, media
Say it, don’t write it: The crawler is a guest on every site it visits, so politeness is a requirement.
The crawler has no users clicking buttons. Its customer is the indexer that reads the pages, and the people who run the sites it visits.
- Start from a list of seed URLs, fetch each page, and follow the links it contains.
- Obey each site’s robots.txt, and never send a site more requests than it can comfortably take.
- Store the HTML of every page fetched, with when and how it was fetched, for the indexer.
- Fetch each URL at most once per visit, and notice when two URLs return the same page.
- Revisit pages, sooner for pages that change often.
Out of scope
- Ranking and the search index itself; the crawler only feeds them
- Running JavaScript, beyond a short section near the end
- Pages behind a login, and filling in forms
- Images, video and other media
Non-functional requirements
• 10B fetches a month ≈ 4k pages/s • Polite: 1 request at a time per site • A dead machine loses no URL • Bounded fetch: 30 s, 5 MB, 5 redirects • A trap can’t eat a site’s whole budget • Revisits go where pages change
Say it, don’t write it: The rate that limits this crawler is not ours. It is the rate each site will take.
- About 4,000 pages a second, which is 10 billion fetches a month.
- Polite: one request at a time to any one site, with a pause after each.
- A crawler machine can die without losing a single URL.
- Every fetch is bounded: 30 seconds, 5 MB and 5 redirects at most.
- A crawler trap cannot use up a site’s whole budget.
- Revisits are spent where pages actually change.
The rate is the one number to work out now, because it decides almost everything else. A month has 30 × 86,400 = 2,592,000 seconds. 10 billion fetches ÷ 2,592,000 seconds is about 3,900 a second. Plan for 4,000. A crawler has no rush hour. It sets its own pace, and runs at it all day.
The other numbers appear in the deep dive that needs them. They are illustrative interview targets, grounded where possible in published crawls, not measurements of any particular search engine.
Core entities
URL(fingerprint, url, site, state, next visit) Site(host, robots rules, next allowed time) Fetch(url, time, status, page key, hash) Seen: 8-byte URL fingerprints per machine
Say it, don’t write it: A URL has a lifecycle: waiting, leased, fetched, done, then due again.
Follow one URL. The parser finds https://news.example/sport/cup-final on the homepage. It computes the URL’s fingerprint, an 8-byte hash of the address. The fingerprint is not in the seen set, so it goes in, and a URL row is written with state “waiting” under the site news.example.
The site row says when news.example may next be fetched, and holds its robots.txt rules. When that time comes, a worker leases the URL, and the row’s state becomes “leased until 10:05”. The worker fetches the page and stores its HTML in object storage. Then it writes a fetch row: 200 OK at 10:01, the storage key, and a hash of the text. The URL row goes back to “waiting”, with a next visit three days away.
Two things are worth noticing. First, a URL has more states than seen and unseen. It can be waiting for its site’s turn, leased to a worker, fetched but not yet parsed, done, or due for a revisit. A crawler that keeps only a yes-or-no seen flag cannot tell a URL that was fetched from one that was lost in a crash.
Second, the site is an entity in its own right. Politeness, robots.txt rules and the address of the server all belong to the site, not to any one URL. Most of this design is about keeping per-site state in one place.
API
POST /crawls {seeds, policy} → crawl id
GET /crawls/:id → counts, budget, errors
frontier.next(worker) → url + lease
frontier.done(lease, status, page key)
frontier.add(links from one page)Say it, don’t write it: The public API is small. The interesting interface is the one between the frontier and its workers.
A crawler has few outside callers. Operators start a crawl and watch it. The interface that matters is inside: how a worker gets work and hands it back.
| Call | Returns | Rule it enforces |
|---|---|---|
| POST /crawls | A crawl ID, and the seeds accepted | The same request ID returns the same crawl, so a retry does not start a second one |
| GET /crawls/{id} | Pages fetched, URLs waiting, errors by site, budget used | Operators can see why a site is slow or skipped |
| frontier.next(worker) | A URL and a lease that ends in 5 minutes, or “nothing yet” | Only a URL whose site’s turn has come |
| frontier.done(lease, …) | OK, or “lease expired” | Only the current lease holder can finish a URL |
| frontier.add(links) | How many were new | Each link goes to the machine that owns its site; the seen set drops repeats |
Two fields exist for a reason. The lease is how the frontier knows a URL is being worked on, and how it gets the URL back if the worker dies. A worker that finishes after its lease ended is told so, and its result is thrown away, because the URL has already gone to someone else. The request ID on POST /crawls makes a start that timed out safe to send again (idempotency).
Step 1: fetch a page, store it, follow its links
Start with the loop. The seed URLs go into the frontier, the list of URLs waiting to be fetched. A fetcher takes the next URL, downloads the page, and writes the raw HTML to object storage such as S3. A parser reads each stored page, pulls out the links, and adds them to the frontier. The loop runs until nothing is left.
Fetching and parsing are separate workers on purpose. A fetcher spends almost all its time waiting for other people’s servers. A parser spends all of its time on the CPU. Keeping them apart lets each scale on its own, and lets a page be parsed again later without being fetched again.
The interactive version of this example is available when JavaScript loads.
Store each page under the URL’s fingerprint and its visit number. A page fetched twice by mistake then overwrites itself instead of making a second copy.
Step 2: be a polite guest
Before fetching any page, the crawler reads the site’s robots.txt. That is a small file at the root of a site, such as https://news.example/robots.txt, saying which paths crawlers may fetch. It is defined by RFC 9309. The crawler fetches it once, and keeps the rules in a cache for up to 24 hours, as the RFC asks.
The answer to that fetch matters as much as the file. A 200 means read the rules. A 404, or any other 4xx, means the site has no rules, so every path is allowed. A 5xx, or no answer at all, means the rules are unknown, and the RFC says to assume everything is forbidden. Google, for one, stops crawling a site for 12 hours after a 5xx on its robots.txt. The two cases look alike in code and mean opposite things.
Inside the file, the longest matching rule wins. Say a shop has “Allow: /shop/” and “Disallow: /shop/cart”. /shop/cart/2 matches both, and the Disallow rule is longer, so it is forbidden. The crawler reads at least the first 500 KiB of the file, and follows up to five redirects to find it, both as the RFC asks. One line people often expect is not in the standard: Crawl-delay. Google ignores it. The crawler sets its own pace per site, and slows down further when the site answers 429 or 503.
The other per-site lookup is DNS. Every fetch needs the site’s IP address. Asking a DNS resolver for it on every one of 4,000 fetches a second is slow, and the answer barely changes. So the crawler caches each site’s address, as long as its DNS record allows.
The interactive version of this example is available when JavaScript loads.
robots.txt says which paths may be fetched. It says nothing about how often, and that is the first deep dive.
Step 3: skip what was already seen
The news homepage links to /sport. So do 40,000 other pages. Without a check, /sport enters the frontier 40,000 times. So before a link joins the frontier, the parser asks the seen set whether this URL is known. Only new URLs pass.
The link has to be put into one standard form first. HTTPS://News.Example:443/sport/../world#top and https://news.example/world are the same page. Lower-case the scheme and host, drop the default port, resolve the “..”, drop the “#top”, which is never sent to the server. Leave the path’s letter case and the query string alone, because /World and /world can be different pages.
The same check works for text. Two URLs can return the same page, such as a print version and the normal one. The parser hashes each page’s text, and a page whose text is already known is stored but not parsed for links again.
The interactive version of this example is available when JavaScript loads.
The seen set is drawn as one box. The deduplication deep dive sizes it for 30 billion URLs and splits it across machines.
Step 4: come back later
A search engine’s copy of a page goes stale the moment the page changes. So every URL keeps its state in a durable URL database: when it was last fetched, what came back, and when it is next due. Apache Cassandra suits this, with the site as the partition key, so one site’s URLs are stored together and read together.
The frontier reads URLs that have come due and queues them like new ones. On a revisit the crawler sends the page’s last ETag in an If-None-Match header. If the page has not changed, the site answers 304 Not Modified with no body, which saves the bytes. It does not save the request. The site still had to answer, and the request still used the site’s turn.
The interactive version of this example is available when JavaScript loads.
On a quiet test crawl of a few sites, this design already works. The deep dives take it to 4,000 pages a second across the web.
A thousand workers share one queue, and the first 300 URLs are on one site. What happens?
The crawl starts from one seed, the news homepage. The parser finds 300 links on it, all on news.example, and puts them at the front of the queue. A thousand workers are free, and each takes the next URL. Within a second, news.example has 300 requests in flight from one crawler.
A big news site might survive that. A small bakery site on a shared server would not. Its server slows down, then returns 503 errors, and its owner blocks the crawler’s addresses. A crawler that behaves like this gets banned from the sites it most needs. So the requirement is one request at a time to any one site, with a pause after each.
The obvious fix is a rule at the head of the queue. A worker takes the next URL only if that URL’s site is free, and otherwise waits. Replay the start. Worker 1 takes the first news.example URL. Worker 2 sees the second news.example URL, finds the site busy, and waits. So do the other 998 workers. The queue still holds thousands of URLs for other sites, and nobody may touch them, because a news.example URL is at the head. The crawl is now polite, and almost completely idle.
Giving each worker its own timer per site does not help either. Worker 1 waits a second before its next news.example request. So does worker 2, and worker 3. Each one is polite on its own. Together they still send a thousand requests a second.
Look at what the workers are asking for. Each one asks for the next URL, and the next URL is the problem. What a worker needs is the next site whose turn has come.
So give every site its own queue of waiting URLs. news.example gets one, bakery.example gets one, and so on. Beside the queues, keep a list of sites ordered by the time each may be fetched again. That list is a min-heap: the site at the top is the one whose turn comes soonest. A worker looks at the top. If that site’s time has come, the worker takes the site’s next URL. If not, no site’s time has come, so the worker sleeps until it does. When a fetch finishes, its site goes back into the heap with a new time.
Replay the start once more. The 300 news.example URLs sit in one site queue. One worker takes one of them. The other workers take the next sites in the heap: bakery.example, shop.example, and thousands more. news.example gets one request, then its pause. Every worker is busy.
How long should the pause be? A fixed second works. Najork and Heydon, writing up their Mercator crawler in 2001, used a pause that adapts (High-Performance Web Crawling). It lasted ten times as long as the last download took. Say a site sends a page in 200 milliseconds. It waits 2 seconds before its next request. Now say it starts taking 3 seconds, because it is struggling. It waits 30. The crawler slows down for the sites that need it, and nobody sets a number per site. Keep a floor of one second. On a 429 or a 503, slow down further. Google does the same, and slows its crawl of a site that answers 429 or 5xx.
Now count the sites this needs. A site that sends a page in 200 milliseconds and then pauses 2 seconds gives one request every 2.2 seconds. To make 4,000 requests a second, 4,000 × 2.2 = 8,800 sites must be taking their turn at any moment. So the frontier needs far more sites ready than it has workers. Najork and Heydon’s rule of thumb, about three site queues for every fetching thread, says the same thing.
The same arithmetic sets a limit for big sites. Say news.example has 3 million pages. At one request every 2.2 seconds, one full pass takes 3,000,000 × 2.2 = 6,600,000 seconds, about 76 days. Hardware on our side cannot shorten that, because the pace is the site’s. So at this default pace a big site is never crawled in full every month. Its important pages are, and the rest are spread over a longer cycle. Google raises its rate for a site that answers quickly and steadily, and lowers it when answers slow down or fail.
The experiment runs three workers over twelve URLs on four sites. The tabs are the shared queue with no rule, the shared queue that waits for its turn, and a queue per site.
The interactive version of this example is available when JavaScript loads.
One more layer decides which URLs are worth a turn at all. The front page of a big newspaper matters more than page 40 of an old forum thread. Mercator used two layers of queues for this. Front queues sort URLs by priority: a URL with a high score, say from how many pages link to it, goes into a high-priority queue. Back queues are the per-site queues above. When a site’s back queue runs dry, it is refilled from the front queues, choosing high-priority queues more often. The front queues rank the URLs. The back queues space the requests.
The gap: Many workers pull from one frontier, and any one site may take only one request at a time.
Option 1: One shared queue, no rule
Every worker takes the next URL, whatever its site.
Works when: Every URL is on a different site, as in a list of homepages.
Breaks when: The first seed puts 300 news.example URLs in a row, and the site gets 300 requests at once.
Option 2: One shared queue, each worker waits for the site
A worker takes the head URL only when its site is free.
Works when: The crawl is small and has few sites, so waiting costs little.
Breaks when: A busy site at the head stops every worker, and the crawl sits idle.
Option 3: A queue per site, and a heap of sites by next turn (start here)
A worker takes the site whose turn comes soonest, then that site’s next URL; the pause is ten times the last download, at least one second.
Works when: Always, for a crawler that visits many sites.
Watch for: It needs thousands of sites in rotation: 8,800 for 4,000 requests a second.
Option 4: Priority queues in front of the per-site queues
Front queues rank URLs by importance and refill each site’s queue, favouring the high ranks.
Works when: Some pages matter more than others, as they do for a search engine.
Watch for: Every URL needs a score before it is queued, which is a pipeline of its own.
In the interview: Open with option 3, and give the arithmetic: 8,800 sites taking turns for 4,000 requests a second. Use option 2 to show why waiting at the head of one queue makes a polite crawler idle. Add option 4 when the interviewer asks which pages get fetched first.
Say this: A shared queue sends one site many requests at once, and waiting at its head leaves every worker idle. I keep a queue per site and a heap of sites ordered by when each may be fetched again. A worker takes the site whose turn comes soonest, and the site then waits ten times its last download time. For 4,000 requests a second that means about 8,800 sites taking turns at once.
The interactive version of this example is available when JavaScript loads.
The second tab is the order of writes that the crash-recovery deep dive below explains. The third is Step 2’s robots.txt rules, as code.
The first version crawls 143 pages a second. How do you reach 4,000?
The first version is one machine running 100 threads. Each thread takes a URL, fetches the page, parses it, and takes the next. Watch one thread fetch one page from a site it has not talked to lately. It asks DNS for the site’s address: 200 milliseconds. It opens a connection and sets up TLS: 300 milliseconds. The server sends the page: 200 milliseconds, the same site as in the last deep dive. That is 0.7 seconds, and the CPU was idle for nearly all of it. 100 threads ÷ 0.7 seconds is about 143 pages a second. The target is 4,000.
The number that matters is how many fetches are in flight at once. Work in flight equals rate times time. That is Little’s law. At 0.7 seconds a fetch, 4,000 a second means 4,000 × 0.7 = 2,800 fetches in flight.
That average hides the servers that never answer. Say 1 fetch in 25 goes to a server that says nothing, and the crawler waits out its full 30-second timeout. The average fetch is then 0.96 × 0.7 + 0.04 × 30 = 1.9 seconds, and 4,000 a second needs about 7,500 fetches in flight. A few dead servers more than double the connections the crawler holds open. So fetchers use asynchronous I/O: one event loop holds thousands of open connections and wakes only when one of them has data.
Now look at the 200 milliseconds of DNS. Mercator’s builders found their threads spent 87% of their time waiting on DNS, because the standard resolver handled one lookup at a time (Mercator). They wrote a resolver that handled many lookups at once, and that cut the waiting to 25%. Caching removes most lookups entirely. The crawler looks up a site’s address once and reuses it for every page on that site, as long as the DNS record allows. The connection helps the same way. A site asked for a page every 2.2 seconds, as in the politeness deep dive, can keep its connection open between requests. A repeat fetch then skips the 300 milliseconds of TLS.
Then the CPU shows up, in the parser. Parsing HTML and pulling out links costs real CPU, and so does TLS. In 2025 one engineer crawled 1.005 billion pages in 25.5 hours on 12 machines with 16 virtual CPUs each (Andrew Chan’s crawl). Parsing was the bottleneck, and TLS took a quarter of all CPU. That is about 900 pages a second per machine, so 4,000 a second is roughly five machines of CPU. This is why fetchers and parsers are separate. Fetchers spend their time waiting, and parsers spend theirs working, so each is scaled to its own need.
Now the network and the disk. Pages average about 200 KB. Common Crawl’s May 2026 crawl stored 2.16 billion pages in 365.56 TiB, about 186 KB a page with headers (Common Crawl). 4,000 pages × 200 KB is 800 MB a second, or 6.4 gigabits a second, spread over the fleet. Compressed, a page takes much less. Common Crawl’s September 2026 crawl, a similar 2.17 billion pages, was 82.79 TiB compressed, about 42 KB a page. 10 billion pages × 42 KB is about 420 TB a month in object storage.
Five machines of CPU is the floor. Double it to ten machines. The fleet then still makes 4,000 a second with a few machines down, and has room for the seen set in the next deep dive. That raises the question of how to split the work. The first idea is to split URLs: hash each URL, and send it to machine hash mod 10. That spreads the load evenly. It also breaks politeness. news.example’s URLs land on all ten machines, and each machine, polite on its own, sends news.example its own request. The site gets ten at once.
So split by site instead. Hash the host name, and let one machine own each site. That machine holds the site’s queue, its place in the heap, its robots.txt rules and its DNS cache. Politeness is a local decision again, because only one machine ever talks to news.example. Use consistent hashing with many virtual nodes per machine (consistent hashing). Adding an eleventh machine then moves about a tenth of the sites. A machine that dies has its sites spread across all the others, not dumped on one.
Splitting by site creates one new job. A page on machine 3 links to sites that machine 7 owns. Each page has about 60 links, so 4,000 pages a second produce 240,000 links a second across the fleet, most of them for other machines. Sending each link as its own message is wasteful. So each machine collects links in one buffer per destination machine, and sends a batch every second or so. The receiving machine checks them against its own seen set and queues the new ones.
Last comes backpressure, because the stages run at different speeds. If the parsers fall behind, stored pages pile up waiting to be parsed. If a few huge sites keep yielding links, their queues grow without limit. Andrew Chan hit this: the frontiers of a few hot sites grew to tens of gigabytes and made machines stop responding. So keep only the head of each site’s queue in memory, say the next 1,000 URLs, with the rest on disk. And when parsing falls behind, fetchers slow down, rather than filling the store faster than anything can read it.
The gap: One machine cannot fetch 4,000 pages a second, and splitting the work must not split a site.
Option 1: One machine, one thread per fetch
Each thread fetches, parses and moves on.
Works when: The crawl is a few sites or a few thousand pages.
Breaks when: 100 threads at 0.7 seconds a page make about 143 pages a second.
Option 2: Many machines, URLs split by URL hash
Hash each URL to one of 10 machines.
Works when: Politeness does not matter, as when crawling your own servers.
Breaks when: Every machine talks to news.example, so the site gets one request from each machine at once.
Option 3: Machines own sites, by hash of the host name (start here)
Async fetchers, cached DNS and open connections, separate parsers, and links batched to the machine that owns their site.
Works when: Always, for a polite crawl of the web.
Watch for: A site with millions of URLs grows a huge queue on its owner.
Fix within it: Keep the head of each queue in memory and the rest on disk.
In the interview: Open with option 3 and derive it. Dead servers push the average fetch to 1.9 seconds, so 4,000 a second means about 7,500 fetches in flight. That asks for async I/O. Show why option 2 breaks politeness in one sentence. Give the CPU figure from a real billion-page crawl if the interviewer asks what the bottleneck is.
Say this: With timeouts in the mix, an average fetch takes about 1.9 seconds, so 4,000 pages a second means about 7,500 fetches in flight. Fetchers use async I/O and cache each site’s DNS and connection, and parsers scale separately because parsing is the CPU cost. I split the fleet by a hash of the host name, so one machine owns each site’s queue, rules and seen URLs. Links for other sites are batched to their owners every second.
The crawler knows 30 billion URLs. How does it tell a new one?
A few months in, the crawler has met links to about 30 billion distinct URLs, three for every page it fetches in a month. Every one of the 240,000 links found each second must be checked: new, or seen before? Most are repeats, like the link to /sport on every page of a news site.
Every link is normalised first, as in Step 3, so one address spelled two ways is checked once. At this scale one more rule pays for itself: strip the tracking and session parameters a site is known to add, such as utm_source or a session ID. /sport?utm_source=mail and /sport are then the same URL.
The simplest answer is then a set of normalised URL strings. A URL averages about 80 characters, so 30 billion of them take 30,000,000,000 × 80 bytes = 2.4 TB. That does not fit in memory, and checking 240,000 links a second against a disk is too slow.
The first saving is to store a fingerprint instead of the URL: a 64-bit hash of the normalised address, 8 bytes. 30 billion fingerprints take 30,000,000,000 × 8 bytes = 240 GB of raw fingerprints. A hash set in memory needs room around them, about twice that. Split across the ten machines by site, as the last deep dive set up, that is about 48 GB each. It fits on a server with 128 GB of memory.
Can two different URLs share a fingerprint? With 64-bit hashes, the expected number of colliding pairs among n URLs is about n² ÷ 2⁶⁵. For 30 billion URLs in one set that is about 24 pairs. Split across machines, only URLs on the same machine can collide, so the real number is smaller still. At most about 24 URLs out of 30 billion would be wrongly called seen. Mercator used 64-bit fingerprints for the same reason.
A machine can die, and its memory with it. So the fingerprints in memory are only a fast copy. The record is the URL database from Step 4: a URL has been seen if it has a row there. The machine that receives a link writes the row first, then adds the fingerprint to its set. When a machine takes over a site, it rebuilds that site’s fingerprints from the rows. And because a URL’s fingerprint lives on the machine that owns its site, the check happens where the link’s batch arrived, in memory, with no extra network call.
Now the tool most candidates name first: a Bloom filter. It is an array of bits. Adding a URL sets a few bits chosen by hashing it. Checking a URL looks at those bits. If any is 0, the URL is certainly new. If all are 1, the URL is probably seen, and may not be. A filter sized for a 1% false-positive rate needs about 9.6 bits per URL. For 30 billion URLs that is 36 GB, against 240 GB of raw fingerprints.
Follow what a false positive does to a crawler. Say bakery.example adds a page, /menu/cakes. Other pages happen to have set all of its bits. The filter says “probably seen”, and the page is dropped. Nobody ever fetches it, and nothing records that it was skipped. About one new URL in a hundred meets this fate. Say the crawler meets 3 billion new URLs a month. Then about 30 million pages a month are silently never crawled.
The experiment builds a tiny filter from six bakery.example pages, then checks /menu/cakes. The first tab lets the filter decide. The second checks the exact fingerprints.
The interactive version of this example is available when JavaScript loads.
On a fleet of ten machines, the exact set wins. Its raw fingerprints are almost seven times the size of the filter, and as a hash set in memory about thirteen times. It still fits. It drops nothing. A filter also cannot grow: past the 30 billion URLs it was sized for, its false-positive rate climbs.
Putting a filter in front of an exact store on disk helps less than it sounds. A filter can only say “certainly new” or “maybe”. Most links a crawler meets are repeats, and every repeat answers “maybe”, so the disk is read anyway. When the set outgrows memory, Mercator’s approach does better: a cache of popular fingerprints in memory, and the full set sorted on disk, checked in batches.
The same idea catches duplicate pages. Mercator found that 8.5% of the pages it fetched were exact copies of pages it already had. A hash of the text catches those. Near-copies are harder: the same article with a different date in the footer has a different hash. SimHash builds a 64-bit fingerprint in which similar texts differ in only a few bits. Google used it over 8 billion pages, calling two pages near-duplicates when their fingerprints differed in 3 bits or fewer (Manku, Jain and Das Sarma). The next deep dive uses it to catch a trap.
The gap: Each of 240,000 links a second must be checked against 30 billion known URLs.
Option 1: A set of URL strings
Keep every normalised URL, and look each link up.
Works when: The crawl knows millions of URLs, not billions.
Breaks when: 30 billion URLs at 80 bytes are 2.4 TB, too big for memory and too slow on disk.
Option 2: A Bloom filter as the judge
About 9.6 bits a URL; a filter hit drops the link.
Works when: Losing some pages is acceptable and memory is scarce.
Breaks when: About 1 new URL in 100 is dropped for ever: 30 million pages a month.
Option 3: Exact 8-byte fingerprints, split by site (start here)
A 64-bit hash of each normalised URL, in memory on the machine that owns the site, backed by the URL rows.
Works when: Always, at this size: 240 GB raw, about 48 GB a machine as a hash set.
Watch for: At most about 24 of 30 billion URLs collide and are wrongly skipped.
Option 4: A memory cache in front of fingerprints on disk
Popular fingerprints in memory, the full sorted set on disk, checked in batches.
Works when: The set outgrows the fleet’s memory.
Watch for: New links wait for the next batch before they can be queued.
In the interview: Open with option 3 and do the arithmetic: 30 billion × 8 bytes, split across machines. When the interviewer mentions a Bloom filter, say what its false positive does in a crawler: a page is never fetched, and nobody knows. Keep option 4 for when the numbers outgrow memory.
Say this: I normalise every link and store a 64-bit fingerprint of it, 8 bytes each. 30 billion URLs take 240 GB raw, about 48 GB a machine as a hash set. The fingerprints are split by site and rebuilt from the URL rows, so a link is checked in memory on the machine that owns its site. A Bloom filter would be about a thirteenth of the memory, but a false positive means a page is never crawled, about one new URL in a hundred.
A calendar has a “next month” link on every page. How does the crawler stop?
events.example has 40 real pages and a calendar. Months 1 to 12 list real events. Every month after that is the same page: the month’s name, “No events”, and a link to the next month. The crawler fetches month 13, finds the link to month 14, and month 14 is a new URL. So is month 15, and month 500. The seen set was built to stop repeats, and nothing here repeats.
Other traps work the same way. A shop’s filters make a new URL for every combination of colour, size, price and sort order. A site that puts a session ID in every link makes a fresh copy of itself for each visit. A broken relative link makes /a/b/a/b/a/b, one level deeper each time. None of these loops back. Each one keeps making new URLs.
Some traps die before a single fetch. Normalising URLs, from the last deep dive, strips the session ID, so every copy of the site collapses into one. The shop’s filters need a limit on the URL itself. Follow at most a few distinct values of any one query parameter per path, and ignore the sort order. A limit on URL length catches /a/b/a/b, because those URLs keep growing.
The calendar passes all three. Its URLs are short, have no parameters, and never grow: /calendar/2027-01, /calendar/2027-02. So the next defence is a budget per site. events.example may use 400 fetches this cycle, and then the crawler moves on. That bounds the damage, and every crawler needs it as a backstop. But on its own it still spends 346 of the 400 fetches on empty months.
A depth limit does stop the calendar. Stop following links more than 10 hops from the site’s home page. Month k is k hops deep, so the crawl stops at month 10, after 51 fetches. But months 11 and 12 had real events, and they are cut. So is every legitimate deep page on other sites: page 30 of a forum thread, or an article reached through a chain of “next” links.
The defence that works reads the pages. After each fetch, the crawler computes the page’s SimHash from the last deep dive. It groups URLs by pattern: /calendar/2027-01 and /calendar/2027-02 both become /calendar/. For each pattern on each site, it compares every new page with the pattern’s pages already fetched. It counts how many pages in a row were near-duplicates of one of them. Month 13 is the first empty month, so its text is new once. Months 14, 15 and 16 are the same empty template, so their fingerprints differ from month 13’s by a bit or two. After 20 near-duplicates in a row, the crawler stops following /calendar/ on that site.
Replay the calendar. The crawler fetches the home page, the 40 real pages and months 1 to 13. All 54 have new text. Months 14 to 33 are near-duplicates, and after the 20th the pattern is dropped. That is 74 fetches, all 54 pages with new text found, and 20 spent learning the pattern was empty.
The experiment crawls events.example three ways. The chart plots pages with new text against fetches, with the site’s budget of 400 marked. The tabs are the seen set alone, a depth limit of 10, and stopping when nothing is new.
The interactive version of this example is available when JavaScript loads.
A real site can look like a trap. An archive of 50,000 different articles all matches /article/*. The near-duplicate test lets it through, because each page’s text is new. Only the site budget stops an archive, so that budget grows with how much new text the site keeps producing, up to a hard cap per cycle. The cap matters, because a trap can also generate text that is random rather than repeated. The crawler keeps a sample of the URLs it refused, so an operator can see that a pattern was cut off and why.
The gap: Some sites generate new URLs without end, and the seen set only stops repeats.
Option 1: A budget per site
Each site may use so many fetches per cycle, up to a hard cap.
Works when: Always, as the backstop.
Breaks when: The calendar still spends 346 of 400 fetches on empty months.
Option 2: A depth limit
Stop following links more than 10 hops from the home page.
Works when: Traps grow by hops, like /a/b/a/b.
Breaks when: Real deep pages are cut, and here months 11 and 12 are lost.
Option 3: Stop a URL pattern when its pages stop being new (start here)
SimHash each page; after 20 near-duplicates in a row, stop following that pattern on that site.
Works when: Always, after normalising URLs and inside the site budget.
Watch for: It spends 20 fetches to learn a pattern is empty.
In the interview: Open with normalisation, which kills session-ID traps before any fetch, and the site budget as the backstop. Then give option 3 as the rule that saves the budget. Use option 2 to show why a limit on how deep a link sits cuts real pages.
Say this: A calendar makes new URLs forever, so the seen set never fires. Normalisation strips session IDs before any fetch, and every site gets a capped fetch budget as the backstop. On top of that I fingerprint each page with SimHash, group URLs by pattern, and stop following a pattern after 20 near-duplicate pages in a row. The calendar costs 74 fetches instead of the whole budget.
A crawler machine dies with 40,000 URLs queued. What is lost?
Start with a simpler first version than the design so far. It saves its seen set to disk, and keeps its queues only in memory, because they change thousands of times a second. A URL goes into the seen set when it is queued.
Machine 7 owns a slice of the web’s sites. It holds 40,000 waiting URLs in its per-site queues, and has 300 fetches in flight. At 10:01 it loses power. 120 of the 300 fetches had already written their page to object storage but had not yet recorded it. The rest were still downloading.
Consistent hashing spreads machine 7’s sites across the other nine machines. They start with empty queues for those sites. That alone is bad: 40,000 URLs are gone. It is worse than it looks, because every one of them is in the seen set on disk. When another page links to one, the seen set says “already seen” and drops it. The URLs are seen and never fetched, and nothing will ever bring them back.
So the queues cannot live only in memory. Every URL’s state is a row in the URL database from Step 4: waiting, leased, fetched, done, or due again at a given time. The row is also what “seen” means, as the deduplication deep dive set up. The in-memory queues and fingerprints are only caches of those rows, rebuilt when a machine takes over a site. The other nine machines read the rows for machine 7’s sites and have the 40,000 waiting URLs back within a minute.
That saves the queue and leaves the 300 in flight. The next question is when a URL counts as done. Mark it done when a worker takes it, and those 300 are marked done. The 180 whose pages never reached storage are lost, for the same reason as before: done, and never fetched.
So mark a URL done last, and use a lease until then. Follow one URL through its states. A worker takes it, and its row changes to “leased until 10:05”. The worker fetches the page and stores it. Then it writes “fetched”, so the page will not be downloaded again, and the lease no longer matters. A parser reads the stored page and batches its links to the machines that own their sites. Each of those machines writes the new URL rows and answers “stored”. Only when every batch is acknowledged does the parser mark the URL done and set its next visit.
Now crash at each step. A fetcher that dies before writing “fetched” leaves the lease to run out at 10:05, and the URL is fetched again. A parse is leased too. A parser that dies leaves the row at “fetched”, and when its parse lease runs out another parser picks up the stored page, with no second download. A batch lost in flight was never acknowledged, so the URL is not done, and the parse is repeated.
Each repeat is harmless. The page is stored under the URL’s fingerprint and its visit number, which only goes up when the URL is marked done. So a repeated fetch overwrites its own copy. Its links go to the frontier again, and every one already has a row, so none is queued twice. The site gets one extra request, and nothing else changes. The crawler promises that no URL is lost. A page may be fetched twice.
The experiment follows machine 7 through the crash. The tabs are the queue in memory, a durable queue that marks URLs done when taken, and a durable queue that marks them done last with a lease.
The interactive version of this example is available when JavaScript loads.
Two cases remain. A page that crashes the parser every time would be parsed again for ever. So each URL counts its attempts, and after three it goes to a dead-letter list for a person to look at.
The harder case is a machine that is cut off from the database but can still reach the web. Machine 7 keeps fetching from its cached queues, while machine 4 takes over news.example. For as long as that lasts, news.example gets requests from both. The fix is to make ownership itself a lease. Each machine holds a lease on its sites, renewed every few seconds, with a number that goes up each time the lease changes hands. Every lease and every “done” the machine writes carries that number, and the database refuses a stale one. A machine that cannot renew its ownership stops fetching those sites. Machine 4 waits for the old ownership lease to run out before it starts. The two never fetch one site at the same time, apart from a request already in flight and clocks that disagree by a moment.
The gap: A machine dies while it holds queued URLs and fetches in flight.
Option 1: Queues in memory
Each machine keeps its site queues in RAM, and the seen set on disk.
Works when: A crash can cost the crawl, as in a quick one-off job.
Breaks when: 40,000 URLs vanish, and the seen set stops them from ever being queued again.
Option 2: A durable queue, marked done when taken
URL rows live in the database, and a worker marks a URL done as it takes it.
Works when: Losing the pages in flight is acceptable.
Breaks when: The 180 fetches that never stored a page are marked done and lost.
Option 3: A durable queue, a lease, and done marked last (start here)
A taken URL is leased for 5 minutes; done is written only after its links are stored by their owners.
Works when: Always. Every step is safe to repeat.
Watch for: Every fetch in flight at the crash is redone; 120 of them are fetched twice.
In the interview: Open with option 3, and give the rule in one line: mark done last, and make every step safe to repeat. Use option 1 to point out that a lost queued URL is worse than it looks, because the seen set blocks it for ever. Bring up ownership leases when the interviewer asks about a network partition.
Say this: Every URL’s state is a row in the URL database, and the queues and fingerprints in memory are only caches of it. A worker leases a URL for 5 minutes. The URL is marked done only after the page is stored and the machines that own its links have stored them. If anything dies, the URL is fetched or parsed again. The repeat is harmless, because the page overwrites itself and every link already has a row.
A news page changes hourly and a blog post never. How often do you revisit each?
The crawler can afford so many revisits a month. Take four pages and 40 revisits between them. The news homepage changes every 2 hours. A product page changes every 3 days. A docs page changes every 10 days. A blog post from 2019 never changes. A copy is fresh while it matches the live page, and the goal is to keep the copies fresh as much of the time as possible. Every page gets at least one visit a month, so the crawler notices if it does change.
The simplest answer revisits every page on the same schedule: 10 visits each, every 3 days. Look at what that buys. The blog post never changes, so every one of its 10 visits finds nothing new. The news homepage changes about 36 times between visits, so it is stale almost all the time anyway. Across the four pages, a copy is fresh 63.1% of the time.
The obvious improvement is to visit each page in proportion to how often it changes. The news homepage changes most, so it gets 37 of the 40 visits, and the other three get one each. The average falls to 38.0%. The news page is still stale most of the time, fresh 10.3% of it, because it changes faster than 37 visits can keep up with. Meanwhile the product page, which one visit every few days would have kept mostly fresh, is visited once and is stale for most of the month.
The result is general. Cho and Garcia-Molina proved it (Effective Page Refresh Policies for Web Crawlers). Visiting every page equally is always at least as fresh, on average, as visiting in proportion to change. Their model assumes changes arrive at random at a steady rate, and the experiment uses the same model.
Now ask where one more visit buys the most freshness. A visit to the blog post buys nothing. A visit to the news homepage buys almost nothing, because the copy is stale again within two hours. A visit to the product page buys a lot. Give each visit, after the one-visit floor, to the page it helps most. The 40 then split as 24 for the product page, 14 for the docs page and one each for the other two. The average rises to 68.0%, the best of the three.
The crawler does not know how often a page changes, so it estimates from history. Each revisit records whether the page had changed. A page that changed at 5 of the last 6 visits is revisited sooner. One that changed at none of them is revisited later. A page that changed at every visit tells you only that it changes at least that often. Keep bounds: no sooner than an hour, and no later than a month. The estimate says how often a page changes. The budget rule above still decides how many visits it gets, so the news homepage keeps its single visit however fast it changes.
The experiment spends 40 visits across the four pages. The tabs are the same schedule for every page, chasing the busiest page, and spending each visit where it helps most.
The interactive version of this example is available when JavaScript loads.
The news homepage looks like a failure, and for the homepage it is. What a search engine needs from a news site is its new articles. A fresh copy of the front page matters far less. So the crawler takes other signals for fast sites. A sitemap lists a site’s URLs with a lastmod date, up to 50,000 URLs per file (sitemaps.org). A news feed lists new articles as they appear. The crawler reads those often, which is cheap, and fetches each new article once.
Importance changes the sums too. A copy of a page that millions of people search for is worth more than a copy of a forgotten one. So weight each page’s freshness by its importance, such as how often it appears in search results. Then give each visit to the page with the largest weighted gain.
Conditional requests make a revisit cheaper. A 304 Not Modified saves the page’s bytes. It still uses the site’s turn and a request slot.
The gap: A revisit budget has to be spread over pages that change at very different rates.
Option 1: Revisit everything on one schedule
Every page every 3 days.
Works when: Pages change at similar rates.
Breaks when: The unchanged blog post wastes 9 of its 10 visits; average freshness 63.1%.
Option 2: Revisit in proportion to change
The page that changes most gets the most visits.
Works when: Pages change at similar rates, where it ties one schedule; it never beats it.
Breaks when: The news page takes 37 visits and stays stale; average falls to 38.0%.
Option 3: Spend each visit where it buys the most freshness (start here)
Estimate each page’s change rate from history, then give each visit to the page it helps most.
Works when: Always, with a floor of one visit, bounds on the interval and weights for important pages.
Watch for: A page that changes faster than you can visit is left stale.
Fix within it: Use sitemaps and feeds for fast sites, and fetch each new article once.
In the interview: Open with option 3, and say the surprising part plainly: chasing the page that changes most makes the crawl less fresh. Mention conditional requests, and say they save bytes, not requests.
Say this: I estimate how often each page changes from whether it had changed at recent visits, and give each revisit to the page it makes most fresh. Chasing the fastest-changing page is a trap: it stays stale anyway and starves everything else. For fast sites I read the sitemap or feed and fetch each new article once. A 304 saves the bytes but not the request.
If they push: the page is empty until JavaScript runs
Some pages arrive as an empty shell and build their content in the browser. The crawler fetches the HTML, finds no text and no links, and moves on. To see the content, it has to run the page in a headless browser such as Chromium. The browser loads the scripts, runs them, and fetches whatever they ask for.
That costs far more than a plain fetch. A page that loads 30 scripts and API calls makes 30 more requests, each to some site, and each counting against that site’s turn. So rendering is a second, smaller stage. The plain fetch runs first. Only pages that look empty, or come from sites known to need it, go to a rendering queue, with its own budget and its own politeness.
If they push: what if a link points inside your own network?
A crawler fetches addresses that strangers wrote. A page can link to http://169.254.169.254/, the address where many cloud servers keep their own credentials. It can link to http://10.0.0.5/admin. Or it can link to a public host name whose DNS answer changes to a private address between the check and the fetch. Each one turns the crawler into a tool for reaching its own network. This attack is called server-side request forgery.
So the crawler checks the address the connection actually uses. It resolves the host name, refuses private, loopback and link-local addresses, then connects to that exact address. It checks again on every redirect, because a public page can redirect to a private one. The OWASP guidance covers the details. Run the fetchers in a network that cannot reach internal services at all, so a mistake in the code is not the only thing in the way.
If they push: how do you know a one-off crawl is finished?
For a one-off crawl, say one university’s website, an empty queue looks like the end. It is not. The last URL was handed out a second ago. Its page is still downloading, then it will be parsed, and it may hold three new links.
So a crawl is finished only when every stage is empty at once. Nothing is waiting or leased. No stored page is waiting to be parsed. No batch of links is still travelling between machines. The URL rows answer the first three, since every URL is waiting, leased, fetched or done. The batches in flight need a counter that goes up when a batch is sent and down when it is acknowledged. A crawl that stops because its budget ran out has a different outcome. It reports that, and does not call itself complete.
Walk one URL through the final design
A parser on machine 3 finds https://news.example/sport/cup-final on the news homepage. The URL’s host hashes to machine 7, so it goes into machine 7’s batch. A second later machine 7 receives the batch, normalises the URL, and computes its fingerprint. It is not in the seen set, so it goes in, and a row is written to the URL database: waiting.
The URL waits in news.example’s queue. When news.example reaches the top of the heap, a worker checks the robots.txt rules, which allow /sport/. It takes the address from the DNS cache and leases the URL until 10:05. The fetch returns 180 KB in 200 milliseconds, so news.example goes back into the heap with a 2-second pause.
The page goes to object storage under its fingerprint and visit number, and the row says fetched. A parser reads it, checks its SimHash against the page fingerprints, finds 61 links, and batches them to their owners. When every owner has stored the new rows, the parser marks the URL done, with its next visit set from how often the page has changed.
The interactive version of this example is available when JavaScript loads.
| Requirement | Where it is met | The trade-off |
|---|---|---|
| FR1 crawl from seeds | Frontier, async fetchers, separate parsers; links batched to the machine that owns their site | Links wait up to a second in a batch |
| FR2 robots.txt and politeness | robots.txt cached 24 hours; a queue per site, a heap of turns, a pause of ten times the last answer | A 3-million-page site takes about 76 days for one pass |
| FR3 store every page | Object storage, keyed by URL fingerprint and visit number | About 420 TB a month, compressed |
| FR4 skip what was seen | Exact 8-byte fingerprints split by site; SimHash for near-duplicate pages | 240 GB of memory across the fleet |
| FR5 revisit | URL database with next-visit times; visits spent where they buy freshness | The fastest-changing pages are left stale on purpose |
How does the answer change for Googlebot, a distributed crawler or an LLM data crawler?
| Interview variant | What carries over | What changes |
|---|---|---|
| Design Googlebot, or a search engine crawler | Everything on this page | Priority and freshness get more time; ranking and the index stay downstream |
| Design a distributed web crawler | Splitting the fleet by host name, batched links, leases | Expect more time on rebalancing when machines join or die |
| Crawl a billion URLs on 10,000 machines with little communication (the follow-up to the Web Crawler Multithreaded coding question) | Hash the host name to a machine, and batch links to their owners | No central frontier at all; each machine owns its sites and their seen set |
| Design a crawler for LLM training data | Politeness, deduplication, traps | One pass, no revisits; clean text and near-duplicate removal matter most, and so do opt-outs |
| Design a web archive, like the Wayback Machine | The frontier and politeness | Every version is kept, and pages are rendered with their images and scripts |
| Design a price or news monitor | Politeness and revisits | A few chosen sites, fetched often; freshness dominates and discovery hardly matters |
What should an answer reach at each level?
| Level | What the answer shows |
|---|---|
| Intern or mid-level | Draws the loop: frontier, fetchers, parsers, a store and a seen set. Reads robots.txt. Knows one site must not get many requests at once. |
| Senior | Keeps a queue per site with a heap of turns. Separates fetching from parsing. Normalises URLs and sizes the seen set. Survives a crash with leases and done marked last. Handles traps with a site budget. |
| Staff | Splits the fleet by host name and explains why a URL hash breaks politeness. Works out 4,000 fetches in flight and the CPU behind them. Chooses exact fingerprints over a Bloom filter, and says what a false positive costs. Detects traps by near-duplicate text. |
| Principal | Sets the crawl budget with the business: how much of a big site each month, and which pages stay fresh. Explains why chasing the fastest-changing page lowers freshness. Covers the risks: request forgery, robots.txt as a convention and not a law, and opt-outs for training data. |
Test yourself with the quiz, then pick another problem from the System Design interview breakdowns.
By GOAT Engineer. Back to all breakdowns. Privacy Policy · Contact.