-
Notifications
You must be signed in to change notification settings - Fork 11k
feat: POC to send multiple ratelimit checks in one request #25157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@chronark is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
| if (onRateLimiterResponse) onRateLimiterResponse(response); | ||
| const { success, reset } = response; | ||
| if (!success) { | ||
| export async function checkRateLimitAndThrowError(req: RateLimitHelper | RateLimitHelper[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be cleaned up but for backwards compatibility I just changed it to accept both a single req or an array
| export { type RatelimitResponse }; | ||
| export const API_KEY_RATE_LIMIT = 30; | ||
|
|
||
| const configs = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before but we're not using the @unkey/ratelimit anymore cause it doesn't support multiLimit yet
| retryConfig: { | ||
| strategy: "backoff", | ||
| backoff: { | ||
| initialInterval: 10, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could use some finetuning
The @unkey/ratelimit sdk used the default backoff, which was much higher, now we have the option to play with it
What does this PR do?
Add a possible implementation of using unkey's multiratelimiting. (https://www.unkey.com/docs/api-reference/v2/ratelimit/apply-multiple-rate-limit-checks)
To application developers this just allows specifying multiple checks in the
checkRateLimitAndThrowErrorfunction:Under the hood this replaces the
@unkey/ratelimitsdk with the underlying@unkey/apisdk while preserving the same behavior around timeouts and fallbacks.It's not really finished and can be cleaned up some more, but I wanted to get some feedback on the direction first before spending time on that.
For API keys I left the original code for now, cause it's irrelevant to show what I have in mind.
I also don't care if you close this cause you want to do it differently :)
I'll leave some more comments throughout this PR.
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
It should just work as before. The check in the middleware now does 2 checks, one for path and one for path+ip
Checklist