Skip to main content

Overview

The F1 Stats Archive implements comprehensive rate limiting to respect the Ergast API’s usage constraints. All data fetchers follow consistent patterns to ensure compliance with both burst and sustained rate limits.

Rate Limit Constraints

The Ergast API enforces the following limits:
  • Burst limit: 4 requests per second
  • Sustained limit: 500 requests per hour
  • 429 response: Rate limit exceeded (requires backoff)

Implementation Patterns

Burst Rate Limiting

Most scripts use a burst limit of 4 requests per second, implemented through request delay calculations:
The delay is calculated as 1 / burst_limit seconds. For 4 requests per second, this equals 0.25 seconds between requests.

Conservative Rate Limiting

Some scripts use a more conservative approach with only 2 requests per second:
From team_points.py:24-59 and driver_points.py:21-46

Sustained Rate Limiting

For long-running operations, track hourly request counts:
From team_points.py:30-41

429 Response Handling

All scripts implement automatic retry with exponential backoff when rate limits are exceeded:
The recursive retry ensures that requests eventually succeed after the rate limit window resets.

Alternative 429 Handling

Some scripts use a longer 60-second wait:
From events.py:32-35 and laptimes.py:56-59

Rate Limiting Constants

Different scripts use different rate limiting configurations:

Best Practices

1. Always Track Request Timing

2. Calculate Sleep Time Dynamically

3. Update Timestamp After Request

4. Implement Retry Logic

5. Monitor Hourly Limits for Long Operations

Simple Rate Limiting Example

For quick scripts without class-based architecture:
From events.py:24-37
Choose between conservative (2 req/sec) and standard (4 req/sec) limits based on your use case. For bulk operations, use the conservative approach.