Skip to content

feat(rate-limit/unstable): add rate limiting module#7237

Open
tomas-zijdemans wants to merge 35 commits into
denoland:mainfrom
tomas-zijdemans:rate-limit
Open

feat(rate-limit/unstable): add rate limiting module#7237
tomas-zijdemans wants to merge 35 commits into
denoland:mainfrom
tomas-zijdemans:rate-limit

Conversation

@tomas-zijdemans

Copy link
Copy Markdown
Contributor

Fixes: #7175

New Rate limit module

This new module offers strategies for controlling how many operations can occur over time. Inspired by .NET’s System.Threading.RateLimiting

The primary API is createRateLimiter, a keyed rate limiter for the common case of "allow key X at most N requests per window." It supports fixed-window, sliding-window, token-bucket, and GCRA algorithms.

For single-resource limiting, use the primitives: createTokenBucket, createFixedWindow, and createSlidingWindow.

The rate limiter supports both in-memory usage and Redis-backed storage for distributed rate limiting across multiple processes or deployments.

Depends on @std/data-structures: Deque for async queue management and RollingCounter for sliding-window segment tracking.

Planned future additions

  • Deno KV store
  • Multiple keys can control rate limiting
  • Defence mechanisms

Note

Recreates #7063, which was closed automatically when I accidentally deleted the head fork. The branch is identical to the original PR head.

tomas-zijdemans and others added 5 commits June 7, 2026 07:10
Casting the setInterval return value with `as number` fails type-checking
on newer Deno libs where it resolves to `Timeout` instead of `number`
(TS2352). Coerce with `Number(...)` instead, matching the convention used
in @std/async/delay.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate Limiting module

1 participant