Ratelock

Strategies

Individual Fixed Window

Per-key fixed windows that start on first request.

Individual Fixed Window works like Fixed Window, but each identifier gets its own independent window that starts when that identifier first makes a request.

How It Works

User A: |──── Window (60s) ────|──── Window ────|
        ↑ first request

User B:         |──── Window (60s) ────|──── Window ────|
                ↑ first request (30s later)

Unlike Fixed Window where all keys share the same window boundaries, each key's window is independent. This prevents the scenario where a new user gets penalized because they joined near the end of a window.

Configuration

Options for the Individual Fixed Window strategy:

Prop

Type

Usage

import { individualFixedWindow } from '@ratelock/local'

const limiter = await individualFixedWindow({
    limit: 10,
    windowMs: 60_000, // 10 requests per minute per user
})

const result = await limiter.check('user:123')
// { allowed: true, remaining: 9, reset: 1716000060000 }

Result Fields

FieldTypeDescription
allowedbooleanWhether the request is allowed
remainingnumberRequests remaining in this key's window
resetnumberEpoch timestamp (ms) when this key's window resets

Fixed Window vs Individual Fixed Window

ScenarioFixed WindowIndividual Fixed Window
User joins at 0:55Gets 5 seconds of windowGets full 60-second window
Window resetAll keys reset togetherEach key resets independently
MemoryLowerSlightly higher (tracks per-key reset)
FairnessLess fair to late joinersFair to all users

When to Use

  • Per-user rate limiting
  • When users join at different times
  • When you want each user to get a full window duration
  • Signup or onboarding flows where new users shouldn't be penalized

How is this guide?

Last updated on

On this page