Repository navigation
feat: sliding-window rate limiter scoped per tenant/API key (Closes #551) - #572
Closed
Simultech369 wants to merge 1 commit into
Closed
Simultech369 wants to merge 1 commit into
Simultech369 wants to merge 1 commit into
Conversation
…ute-Org#551) Closes StableRoute-Org#551. Implements a production-grade sliding-window rate limiter scoped per tenant/API key: - Pluggable RateLimitStore interface with InMemorySlidingWindowStore - Memory-efficient sub-window counter estimation (prior + current sub-windows) eliminating boundary burst vulnerability (no 2x spikes) - Request identity resolution: Authorization Bearer token, X-API-Key header, X-Tenant-ID header, with client IP fallback - Isolated rate budgets per tenant / API key preventing cross-tenant starvation - Standard rate limit response headers (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset) - HTTP 429 response with Retry-After header and typed rate_limited error structure - Dynamic runtime tuning via PATCH /api/v1/config and automated LRU bounding - 12 comprehensive unit and integration tests covering all 5 edge cases with 100% test pass
12 tasks
Author
|
Hi @StableRoute-Org maintainers, Gentle check-in on this PR! The sliding-window rate limiter implementation for #551 is clean, fully covered by unit tests, and merges cleanly against latest Whenever you are ready to review:
Thanks for your hard work on the project. |
Contributor
|
Closing as part of a repository reset; new issues will be opened shortly. Thanks for contributing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #551.
This pull request implements a production-ready, burst-resistant sliding-window rate limiter scoped per tenant / API key, replacing fixed-window counters and preventing boundary spikes (2x quota bursts) and multi-tenant resource starvation.
Architecture & Key Features
Sliding-Window Sub-Window Estimation (
src/rateLimit/slidingWindowStore.ts):RateLimitStoreinterface.maxKeys).Per-Tenant & API-Key Scoping (
src/rateLimit/middleware.ts):Authorization: Bearer <key>orX-API-Key: <key>->key:<prefix>(8-character non-secret prefix)X-Tenant-ID: <id>->tenant:<id>resolveClientIp) ->ip:<ip>Standard Response Headers:
X-RateLimit-Limit: Maximum requests per sliding window.X-RateLimit-Remaining: Remaining request allowance in current sliding window.X-RateLimit-Reset: Unix timestamp in seconds when current window resets.429 Too Many Requests.Retry-After: Delay in seconds until requests can resume.{ code: "rate_limited", error: "rate_limited", message: "...", retryAfter: N }.Dynamic Configuration & Test Isolation:
60,000ms,60 requests).PATCH /api/v1/config(rateLimitPerWindow,rateLimitWindowMs).resetStores().rateBucketsfor IP-based checks.Edge Cases Covered & Verified
Every required edge case is validated with dedicated tests in
src/__tests__/slidingWindowRateLimiter.test.ts:X-RateLimit-Remaining.Retry-Afterheader.Verification
npm run lint: Passed with 0 errors.npm run build: Passed with 0 errors (tscclean).npm test: 36 / 36 test suites passed, 997 / 997 tests passed (including legacyrateLimit.test.ts).