Skip to content

Add structured per-tenant rate limits backed by Postgres token-bucket #451

Description

@thlpkee20-wq

Description

The current rate limiter is per-process. Add structured per-tenant token-bucket limits stored in Postgres (or compatible distributed store) so limits hold across replicas with consistent enforcement.

Requirements and context

  • Must be secure, tested, and documented
  • Should be efficient and easy to review
  • Relevant code: src/middleware/rateLimit.ts, src/security/rateLimit.ts
  • Bucket math must be precise (no double-spend under concurrency)

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b feat/distributed-rate-limit
  • Implement changes
    • Add rate_buckets table with row-level lock semantics
    • Add tenant + route key derivation
    • Add config and admin reset endpoint
  • Validate security and correctness assumptions

Test and commit

  • Run tests
    • npm test
  • Cover edge cases
    • Burst, clock skew, tenant deletion
  • Include test output and notes

Example commit message

feat: distributed token-bucket rate limits

Guidelines

  • Minimum 95 percent test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    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