Sliding window
Sliding window counting blends the previous and current time chunks. It avoids the sharp reset of a fixed window without storing an entry for every request.
Use it when
Section titled “Use it when”- Boundary fairness matters more than minimal computation.
- You want smoother API traffic.
- A close approximation of the recent request count is acceptable.
const limiter = createRateLimiter({ algorithm: Algorithms.SLIDING_WINDOW, limit: 100, windowMs: 60_000, store,});The admission check includes the request currently being evaluated, so the
estimated count never exceeds limit after a request is allowed — a request
that would push the weighted estimate over the limit is denied rather than
admitted first and accounted for afterward.
The algorithm is an approximation. Document that trade-off anywhere your limits form part of a customer-facing contract.