Overview
The TerraQuake API implements rate limiting to ensure fair usage and maintain service quality for all users. Rate limits are applied per IP address using a fixed window approach.Rate Limit Configuration
Default Rate Limit: 100 requests per minute per IP address
- Window Duration: 60 seconds (1 minute)
- Maximum Requests: 100 requests per IP per window
- Reset Behavior: The window resets every minute
Endpoint-Specific Limits
Different endpoints may have different rate limits:| Endpoint Type | Window | Max Requests | Purpose |
|---|---|---|---|
| General API (earthquakes, stations) | 1 minute | 100 | Standard endpoints |
| Authentication | 15 minutes | 50 | Prevent brute force attacks |
| Contact Form | 15 minutes | 20 | Prevent spam |
Rate Limit Headers
Every API response includes rate limit headers to help you track your usage:Header Descriptions
The maximum number of requests allowed in the current window (100)
The number of requests remaining in the current window
Unix timestamp (in seconds) when the rate limit window resets
Number of seconds to wait before retrying (only included in 429 responses)
Handling Rate Limit Errors
When you exceed the rate limit, the API returns a429 Too Many Requests status code:
Error Response
Response Headers
Best Practices
Monitor Rate Limit Headers
Always check the
X-RateLimit-Remaining header to track your usage before making additional requests.Implement Exponential Backoff
When you receive a 429 error, wait for the duration specified in the
Retry-After header before retrying.Cache Responses
Cache API responses to reduce the number of requests. Earthquake data doesn’t change frequently, so caching for 5-10 minutes is reasonable.
Use Pagination Efficiently
Request only the data you need using the
limit parameter. Don’t fetch all results if you only need a subset.Code Examples
Common Questions
What happens if I exceed the rate limit?
What happens if I exceed the rate limit?
You’ll receive a
429 Too Many Requests response with a Retry-After header indicating when you can retry. The request will not be processed.Is the rate limit per API key or per IP?
Is the rate limit per API key or per IP?
Rate limits are applied per IP address. All requests from the same IP share the same rate limit.
Can I request a higher rate limit?
Can I request a higher rate limit?
For production applications requiring higher limits, please contact the TerraQuake team to discuss custom rate limit options.
Do rate limits reset immediately after 1 minute?
Do rate limits reset immediately after 1 minute?
Yes, the API uses a fixed window approach. Each window is exactly 1 minute, and the counter resets at the start of each new window.
Implementation Details
The rate limiter uses a fixed window algorithm with an in-memory HashMap structure:/home/daytona/workspace/source/backend/src/middleware/rateLimiter.js:12-23