Skip to content

feat(rate-limits): make rate limits configurable via environment variables#892

Merged
waleedlatif1 merged 2 commits intostagingfrom
feat/rate-limits
Aug 7, 2025
Merged

feat(rate-limits): make rate limits configurable via environment variables#892
waleedlatif1 merged 2 commits intostagingfrom
feat/rate-limits

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Aug 7, 2025

Summary

Make rate limits configurable via environment variables, default values are what we had before as magic number so no need to set them anywhere

Type of Change

  • New feature

Testing

N/A

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 7, 2025

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

Name Status Preview Comments Updated (UTC)
sim ❌ Failed (Inspect) Aug 7, 2025 3:56am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Aug 7, 2025 3:56am

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR refactors the rate limiting system to use configurable environment variables instead of hardcoded values. The change affects the core rate limiting infrastructure by:

  1. Environment Configuration: Adds 10 new environment variables in env.ts for rate limiting configuration, including window duration (RATE_LIMIT_WINDOW_MS), manual execution bypass limit (MANUAL_EXECUTION_LIMIT), and tier-specific limits for sync/async API executions across free, pro, team, and enterprise subscription plans.

  2. Service Layer Updates: Modifies the RateLimiter service to consume these environment variables through the types.ts module, replacing hardcoded values like 60000 (1 minute window) and 999999 (manual execution limit) with configurable constants.

  3. Test Alignment: Updates the test suite to use the new MANUAL_EXECUTION_LIMIT constant instead of hardcoded expectations, ensuring tests validate actual runtime behavior.

  4. Deployment Configuration: Updates the Helm chart's values.yaml to include the new environment variables with sensible defaults that maintain existing behavior.

This change integrates well with the existing environment management system that uses @t3-oss/env-nextjs and Zod validation. The rate limiting system follows a tiered subscription model where higher-paying customers get increased API execution limits, with separate controls for synchronous and asynchronous operations. The implementation maintains backward compatibility through default values while enabling operational flexibility for different deployment environments.

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it maintains existing behavior through sensible defaults
  • Score reflects well-structured changes that follow established patterns and maintain backward compatibility
  • No files require special attention as all changes are straightforward configuration updates

5 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs August 7, 2025 03:52 Inactive
@waleedlatif1 waleedlatif1 merged commit 7461ddf into staging Aug 7, 2025
3 of 4 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/rate-limits branch August 7, 2025 03:56
waleedlatif1 added a commit that referenced this pull request Aug 7, 2025
…ables (#892)

* feat(rate-limits): make rate limits configurable via environment variables

* add defaults for CI
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…ables (simstudioai#892)

* feat(rate-limits): make rate limits configurable via environment variables

* add defaults for CI
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.

1 participant