Quick revision
The short answer
A good frontier has two levels: front queues ordered by priority feed back queues that each hold one host's URLs, so requests to a host are serialised. A heap keyed by each host's next allowed fetch time tells fetchers which back queue to serve next, and after each fetch the host's time moves forward by its crawl delay, which grows when the host slows down or returns 429 or 503. With far more active hosts than fetchers and asynchronous I/O, no fetcher waits on a slow host; the frontier is partitioned by host hash, spilled to disk, and recrawls are scheduled by change rate within a fixed budget.
What to remember
In this answer, we saw how a shared priority queue caused both the 300 requests per second and the idle fetchers. A two-level frontier separates priority, in front queues, from politeness, in one back queue per host, and a heap of next-allowed times tells fetchers which host is due, with each host's delay coming from robots.txt and growing on slow responses or 429 and 503. Keeping several times more active hosts than fetch slots and using asynchronous I/O keeps fetchers busy, partitioning by host hash and spilling to disk scales the frontier, and recrawls fit in by estimated change rate within a fixed budget.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A good frontier has two levels: front queues ordered by priority feed back queues that each hold one host's URLs, so requests to a host are serialised. A heap keyed by each host's next allowed fetch time tells fetchers which back queue to serve next, and after each fetch the host's time moves forward by its crawl delay, which grows when the host slows down or returns 429 or 503. With far more active hosts than fetchers and asynchronous I/O, no fetcher waits on a slow host; the frontier is partitioned by host hash, spilled to disk, and recrawls are scheduled by change rate within a fixed budget.
Why this question is asked
The symptoms in this question look contradictory: one site gets 300 requests per second, yet the crawler as a whole is slow. Both come from the same mistake, a single shared priority queue that knows nothing about hosts. Interviewers ask about the frontier because it is where politeness, throughput and freshness meet. In this answer, we will see why the shared queue causes both problems, build a two-level frontier, schedule hosts with a heap of next-allowed times, keep fetchers busy, scale the frontier across nodes, and fit recrawl scheduling into a fixed budget.
1Why One Shared Priority Queue Fails Twice
A shared priority queue hands out the highest-priority URLs first. A large news site has thousands of important pages, so its URLs crowd the top of the queue, and dozens of fetchers take them at once. Nothing in the queue knows that they all hit the same server, so the site receives 300 requests per second. That is the politeness failure.
The throughput failure has the same cause. Fetchers that take URLs for slow hosts block for seconds waiting on each response. If many of the top URLs belong to a few slow hosts, most fetchers sit idle in waits, and overall throughput falls to a third of target. The fix for both is to make the frontier aware of hosts.
2A Two-Level Frontier
We split the frontier into two layers. The front queues handle priority: a small number of queues, say 10, one per priority band, where a URL's priority comes from page importance, such as its inbound links, and from how much it needs freshness. A selector takes URLs from the front queues, favouring higher bands but never starving lower ones.
The back queues handle politeness. Each back queue holds the URLs of exactly one host, and a host has only one back queue. A URL taken from the front queues is routed to its host's back queue. Because only one fetch per back queue happens at a time, requests to a host are serialised, and the pace of that host is controlled in one place.
- Front queues by priorityabout 10 bands: importance and freshness need
- Priority selectorbiased toward high bands, no starvation
- Back queues, one per hostthousands per node, each served one fetch at a time
- Heap of next allowed timeswhich host is due next
- Fetchers with async I/Ohundreds of connections each
5 layers, from the top down. Step through them one at a time.
Front queues decide what matters; back queues decide when a host may be contacted.
3Scheduling Hosts With a Heap of Next Allowed Times
A heap, a priority queue that always gives the smallest element quickly, holds one entry per non-empty back queue, keyed by the time at which that host may next be contacted. A fetcher pops the host with the earliest time. If that time is in the future, it waits until then; otherwise it takes one URL from that host's back queue and fetches it.
The crawl delay comes from the host's robots.txt if it sets one, or a default such as one request per second, and it adapts. When responses slow down or the host returns 429 (too many requests) or 503 (unavailable), the delay doubles; when the host is healthy again, it slowly returns to normal. Some crawlers also scale the delay by a multiple of the last response time, which automatically gives slow servers more room. The news site now receives at most one request every second or two, however many of its URLs are important.
4Keeping Every Fetcher Busy
Politeness limits each host to about one request in flight, so throughput comes from spreading work over many hosts. Little's law, which says concurrency equals throughput times latency, gives the size: at a target of 3,000 pages per second with an average fetch of 1.5 seconds, about 4,500 fetches must be in flight. If each host allows one fetch every 2 seconds, each active host supplies at most 0.5 pages per second, so we need at least 6,000 active hosts, and in practice several times that so that slow or empty hosts never leave gaps. A rule of thumb is to keep about three times as many back queues as fetch slots.
The other half is how fetchers wait. A thread per fetch would need thousands of threads. Instead, each fetcher uses asynchronous I/O, for example a non-blocking HTTP client such as Netty or Java's HttpClient with sendAsync, or virtual threads in Java 21 and later, so one fetcher process holds hundreds of connections. A slow host then occupies one cheap connection, not a whole fetcher.
5Scaling the Frontier Across Nodes and Disk
A single machine cannot hold billions of URLs or run every host. We partition the frontier by a hash of the host name across crawler nodes, so all of a host's URLs and its politeness state, its back queue, delay and heap entry, live on one node. Politeness then needs no coordination between nodes. Links discovered on one node that belong to another node's hosts are sent to that node in batches.
The frontier also cannot live only in memory. Each queue keeps a small in-memory head and tail, and the middle spills to disk as append-only files or an embedded store such as RocksDB. Fetchers only ever read from the head, so disk access stays sequential and cheap.
6Where Recrawl Scheduling Fits
Pages change at very different rates: a news front page changes every few minutes, an old blog post almost never. We cannot recrawl everything daily, so we work within a fixed total fetch budget, for example 70 percent for recrawls and 30 percent for new URLs. Each URL gets an estimated change rate from its history: if its content hash changed at the last three fetches, we shorten its interval; if it has not changed in five fetches, we lengthen it.
When a URL's next fetch time arrives, the scheduler feeds it back into the front queues with a priority that combines its importance and how stale it probably is. So recrawls compete with new URLs in the same priority system, and the per-host back queues keep both polite.
| Page | Changed at recent fetches | Next interval |
|---|---|---|
| News front page | 5 of 5 | 15 minutes |
| Product page | 2 of 5 | 3 days |
| Archived blog post | 0 of 5 | 60 days |
7Follow-up questions
How do you handle one host that serves many sites, such as a shared hosting IP?
Politeness should consider the server, not just the host name. Crawlers often group back queues by IP address or by registered domain as well, so a hundred small sites on one server do not receive a hundred times the polite rate.
What happens to a host's queue when its node fails?
The host-hash partition moves to another node, which rebuilds the queue from the disk spill or from the URL store's due dates. Politeness state such as the current delay can be reset to a conservative default, which is the safe direction.
Why not let the site's own speed alone set the pace?
Fast sites could still receive far more than their owners expect. A fixed ceiling per host, plus robots.txt crawl delays and backoff on errors, keeps us welcome even on servers that respond quickly.
8Conclusion
In this answer, we saw how a shared priority queue caused both the 300 requests per second and the idle fetchers. A two-level frontier separates priority, in front queues, from politeness, in one back queue per host, and a heap of next-allowed times tells fetchers which host is due, with each host's delay coming from robots.txt and growing on slow responses or 429 and 503. Keeping several times more active hosts than fetch slots and using asynchronous I/O keeps fetchers busy, partitioning by host hash and spilling to disk scales the frontier, and recrawls fit in by estimated change rate within a fixed budget.
Open with
The shared priority queue knows nothing about hosts, so the news site's important URLs went to many fetchers at once, and fetchers that picked slow hosts sat blocked.
Then, if they want more
I would build a two-level frontier. Front queues are ordered by priority, page importance and freshness need, and back queues each hold the URLs of one host, so requests to a host are serialised. A heap keyed by each host's next allowed fetch time decides which back queue a fetcher serves next.
After a fetch, the host's next time is now plus its crawl delay, from robots.txt or a default like one second, and I raise that delay when responses slow down or the host returns 429 or 503.
To keep throughput, I keep far more active hosts than fetch slots, about three times as many, and use asynchronous I/O so each fetcher holds hundreds of connections; a slow host only costs one connection.
To scale, I partition the frontier by host hash across nodes so each host's politeness state lives on one node, and I spill queues to disk because the frontier holds billions of URLs.
Recrawls fit into the same system: each page's change rate is estimated from whether its content hash changed at recent fetches, and frequently changing pages come back sooner, within a fixed total fetch budget.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Java 21
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design a URL frontier that enforces politeness per host while keeping all fetchers busy...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/bb2028b276/