Architecture
When you calllimiter.limit(identifier):
- Request hits the nearest Unkey location
- Counter is checked and updated
- Decision returned in ~30ms globally
Sliding window algorithm
Unkey uses a sliding window algorithm that provides smooth rate limiting without the “burst at window start” problem of fixed windows. Fixed window problem:- Limit: 100/minute
- User sends 100 requests at 0:59
- Window resets at 1:00
- User sends 100 more at 1:01
- Result: 200 requests in 2 seconds ❌
- Limit: 100/minute
- Considers requests from the past 60 seconds at any point
- No burst exploitation possible
Global consistency
Rate limits are enforced consistently across all regions. A user can’t bypass limits by hitting different geographic endpoints.Response fields
Every rate limit check returns:| Field | Type | Description |
|---|---|---|
success | boolean | true if request is allowed |
limit | number | The configured limit |
remaining | number | Requests left in current window |
reset | number | Unix timestamp (ms) when window resets |
Handling the response
Cost-based limiting
Not all requests are equal. Usecost to deduct more from the limit for expensive operations:
- 100 normal requests, OR
- 20 expensive requests, OR
- Mix of both

