Skip to main content
RLaaS Users Service supports two rate-limiting algorithms, each with different trade-offs in accuracy, memory use, and behavior at window boundaries. You select one via the rate-limiter.use-algo config property.

How it works

The fixed window algorithm divides time into discrete buckets of size windowSize seconds. Each bucket is identified by the index floor(currentTime / windowSize). All requests that arrive within the same bucket share a single Redis STRING key, which is atomically incremented with INCR. The TTL is set on the key when it is first created, so the key expires naturally at the end of the window.Redis key format: rlaas:rate_limit:{userId}:{window}Where {window} is the bucket index (e.g., for a 60-second window, requests at second 120 and second 179 share the same bucket).
local window = math.floor(currentSeconds / windowSize)
local key = KEYS[1] .. ':' .. window
local current = redis.call('INCR', key)
if current == 1 then
  redis.call('EXPIRE', key, windowSize)
end

Trade-offs

Advantages:
  • Very low memory: one INTEGER key per user per active window
  • Simple logic, easy to reason about
Disadvantage — boundary bursts: A user can make up to 2x max-requests in a short period by sending max-requests requests at the very end of window N and another max-requests at the start of window N+1. Both buckets count independently, so the burst goes undetected.

Configuration

rate-limiter:
  use-algo: fixed-window-algo

Switching algorithms

To change the active algorithm, update the use-algo property in your configuration:
rate-limiter:
  use-algo: fixed-window-algo   # or sliding-window-algo
Switching the algorithm will immediately affect new requests. Existing Redis keys from the previous algorithm will expire naturally — you do not need to flush Redis manually.

Comparison

FeatureFixed WindowSliding Window
Memory useLow (1 key/user/window)Higher (1 entry/request)
Boundary burstPossible (2x limit)Prevented
AccuracyApproximateExact rolling window
Redis data typeSTRINGZSET
Config valuefixed-window-algosliding-window-algo

Build docs developers (and LLMs) love