Skip to content
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

feat: increase rate limit for client api endpoints #1904

Merged

Conversation

ShubhamPalriwala
Copy link
Contributor

@ShubhamPalriwala ShubhamPalriwala commented Jan 16, 2024

What does this PR do?

Increases the client side API (including response submissions) rate limits to 100 per 5 mins! 🤞🏼

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Copy link

vercel bot commented Jan 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 11:03am
formbricks-com ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 11:03am

Copy link
Contributor

github-actions bot commented Jan 16, 2024

Thank you for following the naming conventions for pull request titles! 🙏

@ShubhamPalriwala ShubhamPalriwala force-pushed the shubham/for-1716-change-rate-limiting-for-client-endpoints branch from 71a8dd7 to efa8b44 Compare January 16, 2024 11:02
Copy link
Contributor

packages/lib/constants.ts

Instead of using magic numbers for time intervals, it would be more readable to define constants for these values. This will make the code easier to understand and maintain.
Create Issue
See the diff
Checkout the fix

    const ONE_MINUTE = 60 * 1000;
    const FIVE_MINUTES = 5 * ONE_MINUTE;
    const FIFTEEN_MINUTES = 15 * ONE_MINUTE;
    const ONE_HOUR = 60 * ONE_MINUTE;

    export const LOGIN_RATE_LIMIT = {
      interval: FIFTEEN_MINUTES,
      allowedPerInterval: 30,
    };

    export const CLIENT_SIDE_API_RATE_LIMIT = {
      interval: FIVE_MINUTES,
      allowedPerInterval: 100,
    };

    export const SHARE_RATE_LIMIT = {
      interval: ONE_HOUR,
      allowedPerInterval: 30,
    };
git fetch origin && git checkout -b ReviewBot/Impro-aysults origin/ReviewBot/Impro-aysults

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShubhamPalriwala looks great, thanks for the fix 😊

@mattinannt mattinannt added this pull request to the merge queue Jan 17, 2024
Merged via the queue into main with commit e896a73 Jan 17, 2024
13 checks passed
@mattinannt mattinannt deleted the shubham/for-1716-change-rate-limiting-for-client-endpoints branch January 17, 2024 07:21
@connorwinston
Copy link

Is there anyway to override these constants with environment variables?

@mattinannt
Copy link
Member

@connorwinston Why do you want to overwrite them? what problem are you facing?

@connorwinston
Copy link

@mattinannt I would like to increase the number of requests that can be made specifically for shares and the other limits in general, they are pretty low. Additionally, the way I have this hosted/internally protected on our intranet means that some routes receive the same ip regardless of the user, which kind of breaks this. It would be nice to either configure the rate limiter amounts via ENV or disable/enable the ratelimit in general via ENV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants