0Pricing
Web Scraping & Bots · Lesson

Rate Limiting and Respectful Crawling

Learn how to throttle requests, honor crawl-delay, and avoid overloading servers so your scraping stays ethical and sustainable.

Rate Limiting and Respectful Crawling is a free Web Scraping & Bots lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web Scraping & Bots learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Rate Limiting Matters

Even when scraping is legally permitted, hammering a server with rapid requests can degrade the site for real users and get your IP banned.

Respectful crawling means pacing your requests so you gather data without harming the host.

The Cost of a Request

Every request consumes server CPU, bandwidth, and database load. A scraper firing hundreds of requests per second behaves like a denial-of-service attack, even unintentionally.

  • Small sites have limited capacity.
  • Bursts spike server load.
  • Steady, slow traffic is far kinder.

Reading Crawl-Delay

Many robots.txt files include a Crawl-delay directive specifying seconds to wait between requests. Honor it as a baseline minimum.

User-agent: *
Crawl-delay: 10
Disallow: /private/

A Simple Delay

The most basic throttle adds a pause between requests. A fixed delay is fine for low-volume jobs.

import time
import requests

for url in urls:
    requests.get(url)
    time.sleep(2)  # at least 2 seconds between requests

Randomized Delays

Fixed intervals create a robotic, easily-detected pattern. Adding jitter makes traffic look more human and spreads load.

import random, time

delay = random.uniform(1.5, 4.0)
time.sleep(delay)

Token Bucket Throttling

For steadier control, a token bucket permits a fixed average rate while allowing small bursts. Tokens refill over time; each request spends one.

import time

class RateLimiter:
    def __init__(self, rate):
        self.rate = rate
        self.last = time.time()
    def wait(self):
        now = time.time()
        gap = 1.0 / self.rate
        sleep = gap - (now - self.last)
        if sleep > 0:
            time.sleep(sleep)
        self.last = time.time()

Respecting HTTP 429

A 429 Too Many Requests response is the server telling you to slow down. Check for a Retry-After header and back off for that duration.

resp = requests.get(url)
if resp.status_code == 429:
    wait = int(resp.headers.get('Retry-After', 30))
    time.sleep(wait)

Exponential Backoff

On repeated errors, increase the wait exponentially rather than retrying immediately. This relieves a struggling server and improves your success rate.

delay = 1
for attempt in range(5):
    resp = requests.get(url)
    if resp.ok:
        break
    time.sleep(delay)
    delay *= 2  # 1, 2, 4, 8, 16 seconds

Concurrency Limits

Parallel requests speed things up but multiply server load. Cap simultaneous connections with a semaphore so you never exceed a polite ceiling.

import threading
sem = threading.Semaphore(4)  # max 4 in flight

def fetch(url):
    with sem:
        requests.get(url)

Scheduling Off-Peak

Run heavy jobs during the site's low-traffic hours (often overnight in the host's timezone). Combined with throttling, this minimizes your footprint and reduces the chance of disruption.

Caching to Avoid Re-Fetching

The kindest request is the one you never send. Cache responses locally so re-running a job does not re-hit pages you already have. Only fetch what is new or stale.

import os
if not os.path.exists(cache_path):
    resp = requests.get(url)
    open(cache_path, 'w').write(resp.text)
html = open(cache_path).read()

Quick Check

Test your understanding of respectful crawling.

Recap

You learned to crawl respectfully: honor Crawl-delay, add randomized delays, use token buckets, react to 429 with backoff, cap concurrency, and schedule off-peak.

Polite pacing keeps your scraper sustainable and your access intact.

Frequently asked questions

Is the “Rate Limiting and Respectful Crawling” lesson free?

Yes — the full text of “Rate Limiting and Respectful Crawling” is free to read here on the web, and the Web Scraping & Bots course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web Scraping & Bots course, upgrade to CoddyKit PRO.

What will I learn in “Rate Limiting and Respectful Crawling”?

Learn how to throttle requests, honor crawl-delay, and avoid overloading servers so your scraping stays ethical and sustainable. You practise Web Scraping & Bots with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Web Scraping & Bots?

No prior experience is required. Web Scraping & Bots on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Rate Limiting and Respectful Crawling” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Web Scraping & Bots lesson?

Yes. Every Web Scraping & Bots lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Understanding Robots.txt
  2. Terms of Service & Copyright
  3. Ethical Scraping Practices
  4. Rate Limiting and Respectful Crawling
← Back to Web Scraping & Bots