Skip to main content

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
The API uses a fixed window rate limiting algorithm with the following configuration:
  • 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:

Rate Limit Headers

Every API response includes rate limit headers to help you track your usage:

Header Descriptions

integer
The maximum number of requests allowed in the current window (100)
integer
The number of requests remaining in the current window
integer
Unix timestamp (in seconds) when the rate limit window resets
integer
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 a 429 Too Many Requests status code:

Error Response

Response Headers

Best Practices

1

Monitor Rate Limit Headers

Always check the X-RateLimit-Remaining header to track your usage before making additional requests.
2

Implement Exponential Backoff

When you receive a 429 error, wait for the duration specified in the Retry-After header before retrying.
3

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.
4

Use Pagination Efficiently

Request only the data you need using the limit parameter. Don’t fetch all results if you only need a subset.
5

Batch Requests

If you need to make multiple requests, space them out over time instead of sending them all at once.

Code Examples

Common Questions

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.
Rate limits are applied per IP address. All requests from the same IP share the same rate limit.
For production applications requiring higher limits, please contact the TerraQuake team to discuss custom rate limit options.
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:
Source: /home/daytona/workspace/source/backend/src/middleware/rateLimiter.js:12-23