Rate limiting#791
Merged
RUKAYAT-CODER merged 2 commits intoJun 27, 2026
Merged
Conversation
…or escaped braces
Contributor
Author
|
Close: #791 |
Contributor
|
Close: #776 |
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.
Close: #766
Description
Here's a summary of the complete spec:
Design (design.md)
The approach uses a strategy pattern — an IRateLimiterStore interface with two implementations:
InMemoryStore — the existing Map logic, used in dev/test and as a production fallback
UpstashStore — wraps @upstash/ratelimit SlidingWindow over Redis, used in production when env vars are set withRateLimit() stays synchronous and unchanged (zero call-site breakage). A new withRateLimitAsync() is the distributed-capable function that route handlers migrate to incrementally. The key insight: making withRateLimit async would silently break every call site since if (rateLimitResponse) would always be truthy on an unawaited Promise — a complete silent outage.
Tasks (tasks.md) — 8 tasks in 5 waves:
Wave Tasks
1 Install @upstash/ratelimit + @upstash/redis · Document env vars in .env.example
2 Extract InMemoryStore + IRateLimiterStore from existing code
3 Implement UpstashStore with fail-open error handling
4 Implement createStore() factory + withRateLimitAsync()
5 Migrate 25 call sites · Verify existing tests pass · Add distributed tests
Ready to implement? You can click "Start Task" on any task, or ask me to begin.
Related Issue
Closes #766
Type of Change
Checklist