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
- 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
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
src/middleware/rateLimit.ts,src/security/rateLimit.tsSuggested execution
git checkout -b feat/distributed-rate-limitrate_bucketstable with row-level lock semanticsTest and commit
npm testExample commit message
feat: distributed token-bucket rate limitsGuidelines