Overview
- What it does: Ensures that an individual IP cannot exceed a specified rate of requests.
- Common use cases: Throttling malicious traffic, preventing DDoS, controlling bursts.
Basic Configuration
Below is an example showing how to enable per_ip limits:Configuration Fields
- limit Maximum number of requests allowed for each user within the specified window.
-
window
Time frame (e.g.,
1m,30s) for measuring requests. -
actions
- type:
-
reject: Returns 429 status with retry information -
block: Similar to reject but for permanent blocks- retry_after: Seconds to wait before retrying
Window Configuration
Thewindow parameter supports any valid duration string:
s: seconds (e.g., ”30s”)m: minutes (e.g., “5m”)h: hours (e.g., “1h”)d: days (e.g., “1d”)
Response Headers
The rate limiter adds the following headers to each response:Per Limit Type Headers
{type} is one of:
globalper_ipper_userper_fingerprint
Rate Limit Exceeded Response
Implementation Details
Storage and Tracking
- Uses Redis sorted sets for tracking
- Key format:
ratelimit:{level}:{id}:{limit_type}:{key} - Automatic cleanup of expired entries
- Thread-safe operations