Skip to content

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

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

feat(rate-limit/unstable): add rate limiting module#7237
tomas-zijdemans wants to merge 36 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>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	import_map.json
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.60976% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.09%. Comparing base (ad7c87b) to head (388d02d).

Files with missing lines Patch % Lines
rate_limit/_replenishing_limiter.ts 98.36% 0 Missing and 3 partials ⚠️
rate_limit/_keyed_algorithms.ts 98.98% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7237      +/-   ##
==========================================
+ Coverage   95.00%   95.09%   +0.09%     
==========================================
  Files         617      628      +11     
  Lines       51674    52699    +1025     
  Branches     9326     9472     +146     
==========================================
+ Hits        49093    50115    +1022     
  Misses       2038     2038              
- Partials      543      546       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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