robots.txt and crawl politeness
How a crawler reads a site's robots.txt rules before fetching, and how it paces requests to each host so a burst of discovered URLs doesn't overload a small server.
What it is
robots.txt is a plain text file a site serves at /robots.txt, and the Robots Exclusion Protocol is the set of conventions for reading it. The original protocol dates from 1994; RFC 9309, published in September 2022 as a Standards Track document, formalized its grammar and added rules for error handling and caching. The rules are a request that crawlers honor, and it is explicit that they are not a form of access authorization.
The file is made of groups. A group starts with one or more user-agent lines, each naming a crawler's product token, followed by allow and disallow lines with path patterns. A crawler looks for the group whose token matches its own name, comparing case-insensitively, and falls back to the * group when none matches. If no rule in the chosen group matches a URL, or the group has no rules, the URL is allowed. Three characters have special meaning: # starts a comment, * matches zero or more characters, and $ anchors the end of the pattern. Other records such as sitemap may be read by a crawler but must not break a group.
# Example: a small site's robots.txt
User-agent: *
Disallow: /search
Disallow: /cart/
Allow: /cart/help$
User-agent: ExampleBot
Disallow: /
Sitemap: https://www.example.com/sitemap.xmlWhen two rules could apply, the most specific one wins, judged by the length of its path, and an exact tie between an allow and a disallow goes to the allow. Google's parser follows that, picks the less restrictive rule when wildcards conflict, and on groups uses the one with the most specific matching user agent, combining groups that repeat that same token into one and ignoring the other groups in the file.
| What the fetch of /robots.txt returns | What RFC 9309 says | What Google's crawlers do |
|---|---|---|
200 with a parseable file | Follow the rules; the file may be cached, but a cached copy should not be used for more than 24 hours unless the file later becomes unreachable | Use the file; a 500 KiB size cap applies and anything past it is ignored |
A redirect | Follow at least five consecutive redirects, even to another host | Follows at least five redirect hops |
4xx (unavailable) | The crawler may access any resource: no rules apply | All 4xx except 429 are treated as if no robots.txt exists; don't use 401 or 403 to slow a crawl |
5xx or a network error (unreachable) | The rules count as undefined and the crawler must treat the whole site as disallowed; after a long outage, for example 30 days, it may treat the file as unavailable | Stops crawling the site for the first 12 hours while retrying the file; after that, uses the last good copy for up to 30 days while still retrying, and a 503 causes fairly frequent retries; if no cached copy exists at that point, assumes no restrictions |
Politeness is the other half of the concept and the part robots.txt leaves open. A crawler's behavior comes from several policies, and the politeness policy is the one that says how to avoid overloading the sites it visits. robots.txt lets a site say which paths are off limits but says nothing about how often a crawler may come back, even though spacing requests is the most effective way to avoid overloading a server. Some search engines read an extra Crawl-delay line as a number of seconds to wait between requests, and the intervals crawlers have used vary widely: the first proposal was 60 seconds, later crawlers used 10 or 15 seconds, one research crawler used 1 second, and the Mercator crawler waited an adaptive 10 times the time the last download from that server took.
The classic frontier design comes from the Mercator crawler and sets three constraints: one connection open to a host at a time, a polite gap between successive requests to the same host, and high-priority pages moving ahead of low-priority ones. It separates the first two from the third. URLs flow into a set of front queues that handle prioritization, then into back queues that carry the politeness rules, each back queue holding URLs from a single host. A heap keeps, for each back queue, the earliest time its host may be fetched again, and a worker thread takes the queue whose time has come. The split is needed because a plain priority queue tends to fail here: many of the links on a page point to its own site, so the top of the queue becomes a burst against one server.
When to use it
Our advice: a crawler that keeps fetching pages from hosts you don't control should have both halves: a robots.txt check before the first fetch of a URL, and a per-host pacing mechanism that holds no matter how many URLs for that host are waiting. In the frontier, keep priority and politeness in separate structures: priority decides which URL moves from the front queues into a host's back queue, and the host's next-allowed time decides when a fetcher may take from it. A heap of hosts keyed by that time gives the fetcher its next job, and the Mercator recommendation of about three times as many back queues as crawl threads keeps the threads busy while hosts stay spaced.
Choose the delay per host rather than globally. A fixed delay is easy to reason about and easy to explain to a site owner. An adaptive delay, a multiple of the last response time as Mercator used, slows down automatically on a server that is struggling and speeds up on one that answers fast. Bing's crawler reads Crawl-delay as a relative throttle on its default rate, accepts positive whole numbers, and advises keeping the value low, since values above 10 sharply reduce how fresh its index of the site can be.
Treat the server's own signals as politeness input. A 503 says the service is unavailable and a 429 says the client has sent too many requests; both can carry a Retry-After header that tells the client how long to wait, as a delay in seconds or an absolute date. Returning 500, 503 or 429 is also the documented emergency brake a site owner can pull on Google's crawlers, which scale back on their own when a server has trouble responding. A polite crawler of your own should do the same: on a 429 or 503, push the host's next-allowed time out by the Retry-After value or a backoff, rather than retrying the one URL right away.
When not to
Robots rules are aimed at automatic crawlers. Google documents that its own user-controlled fetchers, such as feed subscriptions, don't apply them; that is one vendor's scoping, not a general exemption. If your system fetches a URL because a user pasted it (a link preview, a bookmark importer), our advice is to decide the scope deliberately: a single fetch on the user's behalf is a different case from crawling, and what applies regardless is identifying yourself in the User-Agent and not hammering the host.
Don't reach for robots.txt as a security tool. Listing a path in the file publishes it, and the right tool for anything that must stay private is proper access control. The same goes from the crawler's side: a 401 or 403 on /robots.txt reads as "no rules" (see the table above), so a site that wants a slower crawl should use a 429 or 503 instead.
A crawler that visits sites you operate yourself, or a job that fetches a known list of a few hundred URLs across many hosts, doesn't need front and back queues. Our advice there: a single queue plus a map from host to last-fetch time, and a sitemap or a direct feed from your own systems instead of link discovery. Build the two-tier frontier when the number of hosts is large and the per-host backlog can grow unbounded.
Don't rely on Crawl-delay to protect a site, in either direction. Bing reads it, but the parser whose rules the table above describes ignores records other than allow, disallow and user-agent, so the line changes nothing for that crawler. A crawler you write can honor it, but a site that needs a hard limit should rate-limit at the server and answer 429 or 503, which the crawler sees whether or not it reads the line.
Compared
| Way to pace a host | How it decides the gap | When it's the right choice | Where it falls short |
|---|---|---|---|
Fixed delay per host (a few seconds, or the site's Crawl-delay) | A constant wait after each fetch | Small or medium crawls, and sites that published a delay; simple to explain and audit | Too slow for a large site that could take more, too fast for a struggling one |
Adaptive delay (k times the last response time) | A slow response widens the gap; a fast one narrows it | Broad crawls over hosts of very different capacity | A single slow response from a healthy host over-throttles it; needs a floor and a ceiling |
A single connection per host | Concurrency, not time: at most one request in flight | Worth having alongside a delay in any crawl; it bounds damage from a bug in the delay logic | On its own, it still allows back-to-back requests with no gap |
Honor 429 and 503 with Retry-After | The server names the wait | Whenever the server sends one; it's the clearest signal you can get | Reactive: by the time the server sends one it may already be under strain, and a 503 can also mean planned downtime rather than overload |
In a picture
How to say it in an interview
The common mistake
Quiz
Questions that use this
Hear it in
Related
Sources
- RFC 9309: Robots Exclusion Protocol
- Google Search Central: How Google interprets the robots.txt specification
- Google Search Central: Reduce the Google crawl rate
- Google Search Central: Troubleshoot Google Search crawling errors
- Wikipedia: Web crawler
- Crawlex blog: URL frontier design, from Mercator to modern priority-queue crawlers
- MDN: Retry-After header
- Bing Webmaster Blog: Crawl delay and the Bing crawler, MSNBot