Effect Sliding Window Rate Limit
Rate limiting that stops the fixed-window boundary burst with O(1) state. A fixed window admits 100 at 0:59.9 and 100 more at 1:00.0, the exact spike it was meant to forbid, because the window snaps to a grid. A true sliding log is accurate but stores a timestamp per request, a memory-exhaustion vector; the sliding-window-counter keeps just the current and previous window counts and weights the previous by how much of it still overlaps, bounding both the burst and memory to O(1) per key. The decision and count bump happen in one atomic Ref.modify so two concurrent requests at the limit cannot both slip through. The demo halves the boundary burst and refills as the window slides. Pinned to effect 4.0.0-beta.98.
npx shadcn@latest add https://ui.aryank.space/r/effect-sliding-window-rate-limit.jsonInstalls from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.
A fixed window snaps to a grid, admitting 10 at 0:59.9 and 10 more at 1:00.0. Twenty requests slip through in a millisecond straddling the reset: the boundary burst it was meant to forbid.