Overview
- What it does: Controls how many requests each user (identified via header) can make.
- Common use cases:
- Preventing account-level abuse.
- Ensuring fair usage among registered or authenticated users.
Basic Configuration
Below is an example showing how to enable per_user limits:User Detection
The system detects user IDs from the following headers:X-User-IDX-User-IdX-UserIDUser-ID
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 informationblock: Similar to reject but for permanent blocks
- retry_after: Seconds to wait before retrying
- type:
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