Skip to content

Implement tiered rate-limit policies in rateLimiter driven by API key plan tier #389

Description

@greatest0fallt1me

Description

The gateway currently uses a single token-bucket per key in src/services/rateLimiter.ts with one default maxRequests/windowMs pair. To support paid plans and abuse control, we need per-tier policies (e.g. free, pro, enterprise) resolved from the API key record so that /v1/call/* enforces the correct ceiling for each tier without code changes.

Requirements and Context

  • Extend RateLimiterConfig to accept a tier -> { maxRequests, windowMs } map and a tier resolver that reads from apiKeyRepository
  • Wire gatewayApiKeyAuth middleware to set res.locals.apiKeyTier so proxyRoutes passes it into rateLimiter.check
  • Keep backwards-compatible defaults when no tier is present
  • Must be secure, tested, and documented
  • Should be efficient and easy to review

Suggested Execution

  1. Fork the repo and create a branch
    git checkout -b feature/tiered-rate-limits
  2. Implement changes
    • src/services/rateLimiter.ts
    • src/middleware/gatewayApiKeyAuth.ts
    • src/routes/proxyRoutes.ts
    • src/repositories/apiKeyRepository.ts
  3. Test and commit
    • npm test -- rateLimiter
    • Cover edge cases (missing tier, unknown tier, hot-reload)
    • Include test output and notes in the PR

Example commit message

feat: tiered rate limit policies driven by api key plan

Acceptance Criteria

  • rateLimiter.check honors per-tier maxRequests/windowMs
  • Unknown tier falls back to default with a warning log
  • Tests assert each tier ceiling and refill behaviour
  • Docs added under docs/ describing tier config

Guidelines

  • Backend (Node/TS): real service/route/module paths, tests with Jest, input validation, error handling, minimum 90% test coverage
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GRANTFOX OSSGrantFox open-source campaign taskMAYBE REWARDEDMay be rewarded under the GrantFox campaignOFFICIAL CAMPAIGNOfficial GrantFox campaign issueStellar WaveIssues in the Stellar wave programapiAPI endpoint/contract workbackendBackend service workperformancePerformance/efficiency

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions