Politeness and robots.txt

How a crawler avoids burdening the sites it visits. Rate limits and one connection per host, identifying the crawler, and the Robots Exclusion Protocol, with its rules for matching, error handling, and caching as standardized in RFC 9309, and where Python's parser departs from the standard. Worked problems on rates, wildcard rules, and the hosts a thread needs to stay busy.

A crawler that waits about ten times its last fetch from a host before contacting it again occupies any server about 1/11 of the time, some 9 percent, whatever the server's speed, and slows down when the server does. The cost falls on the crawler: with a wait of $k$ times the fetch, one thread needs $k + 1$ hosts in rotation to stay busy. Under RFC 9309 (2022), robots.txt rules are read by longest match regardless of order, a crawler obeys only its own group, a 4xx response for the file permits everything, and a 5xx response or network failure permits nothing. Python's urllib.robotparser applied the first matching rule and ignored wildcards until versions 3.13.14, 3.14.5 and 3.15.0 beta 1 (2026).

The toy crawler in what a web crawler does fetched as fast as it liked. A crawler built to fetch hundreds of pages a second could, if nothing stopped it, send all of them to one server. That server belongs to someone else, who pays for every request and gets nothing in return. How fast may a crawler fetch from one server, and how does the server's owner say which pages it may fetch at all? Common practice answers the first question with a wait of about ten times the duration of the last fetch, and the robots.txt file, read by the rules of RFC 9309, answers the second.

Politeness is the set of practices that keep a crawler's cost acceptable to the owners of the servers it visits. It matters ethically, since a careless crawler can slow or break a small site. It matters practically too, since site operators block crawlers that misbehave. Manning, Raghavan, and Schütze (2008, §20.1.1) list it with robustness as one of the two features a crawler must have.

Here is the route. First we derive what the standard rate limit does to a server and to the crawler. Then we look at how a crawler identifies itself. Next we read a robots.txt file under the rules of RFC 9309. Then we check where Python's own parser departs from the standard. Worked problems close the article.

Rate limits

The most important rule is the simplest: requests to one server must not be sent too quickly. Common practice is to keep at most one connection open to a host at a time and to wait between requests to the same host. How long to wait is the interesting part.

A common heuristic sets the wait adaptively, at about ten times the duration of the last fetch from that host. Manning, Raghavan, and Schütze (2008, §20.2.3) describe it, and the Mercator crawler used it in production crawls (Najork and Heydon, 2002). A server that responds slowly, perhaps because it is busy, is automatically visited less often.

Here is what the rule guarantees, in one sentence: whatever the server's speed, the crawler occupies it about one-eleventh of the time. The argument is short. If a fetch from a host takes $d$ seconds and the crawler then waits $10d$ before the next, each cycle lasts $11d$. Of that, the server spends $d$ serving the crawler. So the crawler's share is $d / 11d = 1/11$, about 9 percent, and $d$ cancels.

In absolute terms the rate adapts. A host that answers in 0.1 seconds can be fetched once every 1.1 seconds, about 78,500 times a day. One that takes half a second is fetched at most once every 5.5 seconds, about 15,700 times a day.

Example (a server under load). When a server that usually answers in 0.1 seconds comes under load and starts taking 0.5 seconds, the crawler does not take a larger share of the struggling server's time. Its share stays at 1/11, because $d$ cancels. What changes is the rate, which falls from about 78,500 fetches a day to about 15,700. The crawler slows down with the server, without having to detect the load at all.

A crawler with many threads must enforce this across all of them. The URL frontier does it by keeping a separate queue for each host and giving each queue to one thread at a time. The timeline below comes from the small frontier traced in crawler architecture: one thread, four hosts with different response times, and the ten-times rule.

Fetches (solid bars) and enforced waits (hatched) for four hosts served by one crawler thread. Each wait is ten times the fetch before it, so the slow host b.org is not visited again for 5 seconds. Notice the gaps where no bar appears: the thread switches between hosts during the waits, and is idle when no host is due.
Fetches (solid bars) and enforced waits (hatched) for four hosts served by one crawler thread. Each wait is ten times the fetch before it, so the slow host b.org is not visited again for 5 seconds. Notice the gaps where no bar appears: the thread switches between hosts during the waits, and is idle when no host is due.

Two things are visible in it. Requests to any one host are spread out, while the thread moves between hosts to fill the waits. And with only four hosts, the thread is idle much of the time. It is busy for 2.4 of the 6.2 seconds, because every host is still in its waiting period.

So politeness costs a crawler nothing in total throughput only when it has many hosts to choose from. Croft, Metzler, and Strohman (2010, §3.2.2) give the scale of "many". A crawler that fetches 100 pages a second, and may contact each server at most once every 30 seconds, needs URLs from at least $100 \times 30 = 3{,}000$ different servers waiting in its queue to keep busy.

Servers can also ask a crawler to slow down. A response with status 429 (Too Many Requests) or 503 (Service Unavailable), especially with a Retry-After header, means the crawler should back off from that host, not retry at once.

Identifying the crawler

Operators also want to know who is visiting. Every HTTP request carries a User-Agent header. A polite crawler sends a name that is distinct from any browser's. With it goes a URL or email address where the site's operator can learn what the crawler is and how to contact its owner. Operators who find unfamiliar traffic in their logs can then decide whether to allow it, write robots.txt rules for it, or ask for changes, rather than blocking it outright.

The Robots Exclusion Protocol

Rate limits govern how often a crawler visits. The site's owner may also want to say where it may not go at all. Martijn Koster proposed the Robots Exclusion Protocol for this in 1994, and crawlers followed it for nearly three decades as an informal convention. It was standardized as RFC 9309 in 2022 (Koster, Illyes, Zeller, and Sassman, 2022). A site publishes its rules in a plain text file at the root of the host, such as https://example.com/robots.txt. A crawler fetches that file before anything else on the host and obeys it.

The file consists of groups. Each group begins with one or more User-agent lines naming the crawlers it applies to, followed by Allow and Disallow rules giving path prefixes. A group for * applies to any crawler without a group of its own. A Sitemap line belongs to no group. It gives the location of a sitemap listing the site's URLs.

The example below is Croft, Metzler, and Strohman's (2010, Figure 3.3), and the rest of this article reads it under the RFC's rules.

User-agent: *
Disallow: /private/
Disallow: /confidential/
Disallow: /other/
Allow: /other/public/

User-agent: FavoredCrawler
Disallow:

Sitemap: http://mysite.com/sitemap.xml.gz

Under this file, crawlers in general may fetch anything except paths under /private/, /confidential/, and /other/, but they may fetch paths under /other/public/. A crawler named FavoredCrawler is matched by its own group, whose empty Disallow forbids nothing, so it may fetch everything.

That summary relies on a rule it has not stated. The path /other/public/c.html matches both Disallow: /other/ and Allow: /other/public/. The longer rule wins, here the Allow, and it does not matter that the Disallow line comes first.

Matching rules

RFC 9309 (§2.2) fixes that rule, and settles several other points that the original convention left open:

  • The most specific rule wins. When several rules match a path, the one with the longest path pattern applies, regardless of the order of the lines. That is why /other/public/c.html is allowed above: Allow: /other/public/ is longer than Disallow: /other/. If an Allow and a Disallow match equally, the RFC says the Allow should apply.
  • A crawler obeys one group. It uses the group whose User-agent matches its name, compared without regard to case. Only if there is none does it use the * group. The rules of its own group are not combined with those of the * group, though several groups naming the same crawler are merged into one.
  • Matching is case-sensitive (the RFC says it should be), and * (any characters) and $ (end of the path) may be used in patterns.

Applied to the example file, a crawler without a group of its own uses the * group, finds every rule whose path is a prefix of the requested path, and keeps the longest:

Path requested Rules that match (pattern length) Longest Result
/index.html none allowed
/private/a.html Disallow: /private/ (9) Disallow disallowed
/other/b.html Disallow: /other/ (7) Disallow disallowed
/other/public/c.html Disallow: /other/ (7), Allow: /other/public/ (14) Allow allowed
/otherwise.html none allowed

The last row is a reminder that rules are prefixes of the path as characters, not directories. Disallow: /other/ does not match /otherwise.html, because of the final slash, but Disallow: /other would.

Example (a longer Disallow). If the file also contained the line Disallow: /other/public/c in the * group, a general crawler could no longer fetch /other/public/c.html. Three rules now match: Disallow: /other/ (7 characters), Allow: /other/public/ (14) and Disallow: /other/public/c (15). The longest is the new Disallow, so the path is disallowed. Other files under /other/public/, such as /other/public/d.html, are still allowed, because the new rule does not match them.

When the file is missing or unreachable

So far the crawler has had a file to read. Often it does not. The status code of the robots.txt request then decides what the crawler may do (RFC 9309, §2.3.1):

  • Success (2xx): parse and obey the file.
  • Redirect (3xx): follow it; the RFC says a crawler should follow at least five consecutive redirects.
  • Unavailable (4xx, such as 404): the site has no rules, and the crawler may fetch anything.
  • Unreachable (5xx or network failure): the crawler must assume that everything is disallowed. If the error persists for a long period, for which the RFC gives 30 days as an example, it may fall back to a cached copy, or treat the file as unavailable.

Example (a common misstatement). "A crawler that cannot read the rules is free to ignore them" is true of one failure and false of the other. The RFC treats the two differently, and the asymmetry is deliberate. A missing file is a statement that there are no restrictions. A server error says nothing, and an unreachable server is a poor one to start crawling. Crawlers may cache robots.txt, but the RFC says they should not use a cached copy for more than 24 hours unless the file has become unreachable (§2.4), so that changes take effect within a day.

Crawl-delay and other extensions

Many robots.txt files contain a Crawl-delay line giving a number of seconds to wait between requests. It is not part of RFC 9309. Some crawlers honor it and others do not: Google's documentation of its own parser lists user-agent, allow, disallow and sitemap as the fields it supports and names crawl-delay as one it does not (Google Search Central, n.d.). A crawler that honors it should still apply its own limits as well.

What robots.txt is not

A common misreading treats a Disallow line as protection. The protocol is a request, not a lock. A malicious crawler can ignore it, and a robots.txt file listing private paths tells everyone where they are. It is not a security mechanism, and content that must not be fetched needs authentication. It is also not a statement of legal permission. Terms of service, copyright, and data protection law apply whether or not a path is disallowed.

Pitfalls in Python's parser

The rules above are the standard. A crawler written in Python can check them with the standard library's parser, urllib.robotparser, which predates RFC 9309. Does it follow them? Until 2026 it differed from the standard in several ways:

  • It applied the first matching rule in the file, not the most specific one. Run on the file above, it disallowed /other/public/c.html, because the Disallow: /other/ line comes first. Under RFC 9309, the longer Allow rule wins and the path is allowed. In the opposite order, Allow: /a/ followed by Disallow: /a/b/, it allowed /a/b/x, which the standard disallows.
  • It did not support the wildcards * and $ in paths. It treated them as ordinary characters, so a rule such as Disallow: /*.pdf matched nothing and every PDF was allowed.
  • It did not merge groups that name the same crawler. Only the first such group was used.

Python's changelog records the change as "Support RFC 9309 in urllib.robotparser" (issue gh-138907), under 3.15.0 beta 1 and under the maintenance releases 3.13.14 and 3.14.5, all three released in May and June 2026 (Python Software Foundation, 2026). From those versions on, the parser implements the longest match, the wildcards, and the merging of groups. Older versions, including every release of 3.12 and earlier, still behave as described. Their differences err in both directions, so the parser can fetch more than a site has asked to allow, as well as less.

A crawler that must follow the standard on such a version needs a parser that implements it, such as the protego package. At the least, someone should read the target site's robots.txt by eye to see whether any of these cases arise. One difference remained in the parser's source at the time of writing (November 2026; the method read in Lib/urllib/robotparser.py): a 401 or 403 response for robots.txt makes it disallow the whole site, where RFC 9309 treats any 4xx response as meaning that there are no rules. The three differences listed above are checked in tools/experiments/crawling/examples.py in the site repository, run on Python 3.11, which has the older behavior. The same script checks the 401 and 403 behavior on that version, by handing the parser those status codes without a network request; for the newest versions it was read from the source.

Worked problems

The course text has no exercises on rate limits or robots.txt. Problem 3 is built on its Exercise 20.3, and the others are posed on this article's examples. The numbers are checked in examples.py and frontier_sim.py.

Problem 1 (share and rate). A host answers in 0.25 seconds. Under the ten-times rule, how often can it be fetched and what share of its time does the crawler take? What multiple would hold the share to 5 percent?

Each cycle is one fetch and one wait: $0.25 + 10 \times 0.25 = 2.75$ seconds. A day has 86,400 seconds, so the host can be fetched $86{,}400 / 2.75 = 31{,}418$ times a day. The share is $0.25/2.75 = 1/11$, about 9.1 percent, as for every host.

With a wait of $k$ times the fetch, the cycle is $(k+1)d$ and the share is $d/((k+1)d) = 1/(k+1)$. A share of at most 5 percent needs $1/(k+1) \le 0.05$, that is $k \ge 19$. With $k = 19$ the cycle is $20 \times 0.25 = 5$ seconds and the host is fetched $86{,}400/5 = 17{,}280$ times a day.

Problem 2 (rules with wildcards). A site's robots.txt has one group:

User-agent: *
Disallow: /search
Allow: /search/about
Disallow: /*.pdf$
Allow: /docs/

Under RFC 9309, which of these paths may a crawler fetch: /search/about/team, /searching, /docs/manual.pdf, /docs/manual.pdf?download=1, /a/b/report.pdf?

For each path, list the rules whose pattern matches it from the start of the path, with * standing for any run of characters and a final $ requiring the path to end there. The longest pattern wins.

Path Rules that match (pattern length) Result
/search/about/team Disallow: /search (7), Allow: /search/about (13) allowed
/searching Disallow: /search (7) disallowed
/docs/manual.pdf Disallow: /*.pdf$ (7), Allow: /docs/ (6) disallowed
/docs/manual.pdf?download=1 Allow: /docs/ (6) allowed
/a/b/report.pdf Disallow: /*.pdf$ (7) disallowed

Three rows deserve a remark. /searching is disallowed because Disallow: /search is a prefix of characters, not a directory, as in the article's last table row. /docs/manual.pdf is disallowed although it lies under an allowed directory, because the wildcard rule is the longer pattern, 7 characters against 6. The same file with a query string is allowed: the $ requires the URL to end in .pdf, and with ?download=1 it no longer does, so only the Allow matches. A site that wants to block such URLs too would write Disallow: /*.pdf without the $.

Problem 3 (hosts needed to keep a thread busy; after Exercise 20.3). The course text gives two rules of thumb, which its Exercise 20.3 calls hard constants: a wait of ten times the last fetch, and about three back queues for each crawler thread, the second a recommendation of Mercator's designers. Exercise 20.3 asks how the two are related. Under a simple model, find how many hosts one thread needs in rotation to stay busy, and what three hosts give it.

Take the model in which every fetch takes the same time $d$ and every host always has another URL waiting. After a fetch, a host is unavailable for $10d$, so each host can give a thread at most $d$ of work in every $11d$ of time. With $n$ hosts in rotation, the thread has at most $nd$ of work in every $11d$. It is therefore busy at most the fraction

$$\min\left(1, \frac{n}{11}\right)$$

of the time, and it reaches full use only with $n \ge 11$ hosts. A simulation of this model in frontier_sim.py agrees to within 0.002: about 0.091 for one host, 0.273 for three, 0.545 for six, and 1 from eleven hosts on.

So the two constants are linked through the quantity $k + 1$, where $k$ is the wait multiple. A thread needs $k + 1$ hosts to stay busy on fetching alone, and raising the multiple raises the number of back queues each thread needs. In this model three back queues a thread would keep a thread fetching only $3/11 = 27$ percent of the time. The model counts only the timed fetch as work, though. If the thread also spends a time $c$ on each URL after fetching it (parsing, extracting links, checking for duplicates), while the host's wait runs, it handles one URL every $d + c$ seconds. Each host still offers one URL every $11d$, so the thread is kept busy by $11d/(d + c)$ hosts. Three hosts suffice when $d + c = 11d/3$, that is, when the other work on a URL takes $8/3 \approx 2.7$ times as long as the fetch. The simulation agrees: with $c = 8d/3$ and three hosts the thread is busy all of the time and fetching $3/11$ of it, and with $c = d$ it is busy only $6/11$ of the time. So the model shows that the two constants are consistent only if most of a thread's time goes to work other than fetching. It does not show that this is why Mercator's designers chose three. The course text gives both constants as rules of thumb and does not derive one from the other.

Problem 4 (what the status code permits). A crawler requests robots.txt from four hosts and receives status 404, 403, 503 and 200 with an empty file. What may it fetch from each under RFC 9309?

  • 404: everything. A 4xx status means the file is unavailable, and the crawler may access any resource.
  • 403: everything, by the same rule, since the RFC makes no exception among the 4xx codes. Python's parser departs from the RFC here and disallows the whole site, as noted above.
  • 503: nothing. A 5xx status means the file is unreachable, and the crawler must assume a complete disallow until it can read the file, or until the failure has lasted long enough to fall back on a cached copy.
  • 200, empty file: everything. The file was read and contains no rule, so no path is disallowed.

What we have learned

Politeness has two halves. Waiting ten times the last fetch keeps a crawler's share of any server near one-eleventh, at a cost in throughput unless many hosts are waiting. And under RFC 9309 a site's rules are read by longest match, with a missing file permitting everything and an unreachable one nothing.

Both halves must be enforced across hundreds of threads, while the crawler also tries to fetch important pages first. Crawler architecture shows how a crawler is organized to do that, and builds the frontier that enforces the waits.

References

  • Croft, W. B., Metzler, D., and Strohman, T. (2010). Search Engines: Information Retrieval in Practice, section 3.2. Addison-Wesley. record · 12 pages
  • Google Search Central (n.d.). How Google interprets the robots.txt specification. Google developer documentation. developers.google.com/search/docs/crawling-indexing/robots/robots_txt (accessed November 2026). record
  • Koster, M. (1994). A standard for robot exclusion. Published on the web at robotstxt.org. record
  • Koster, M., Illyes, G., Zeller, H., and Sassman, L. (2022). Robots Exclusion Protocol. RFC 9309, Internet Engineering Task Force. record · 2 pages
  • Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, sections 20.1–20.2. Cambridge University Press. record · 102 pages
  • Najork, M., and Heydon, A. (2002). High-performance web crawling. In J. Abello, P. M. Pardalos, and M. G. C. Resende (Eds.), Handbook of Massive Data Sets, 25–45. Kluwer Academic Publishers. record · 2 pages
  • Python Software Foundation (2026). Changelog. Python documentation. docs.python.org/3/whatsnew/changelog.html (accessed November 2026). The entry for issue gh-138907 appears there under Python 3.15.0 beta 1, and under 3.13.14 and 3.14.5 in the changelogs of those versions (docs.python.org/3.13/whatsnew/changelog.html and docs.python.org/3.14/whatsnew/changelog.html). record · 2 pages

Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 9 revisions