Skip to content

BFF Rate Limiter upgraded to Redis multi-dimensional rate limiting. #43

Description

@TszHinAk

Current Status

BFF currently uses InMemoryRateLimiter in bff/src/rate-limit.ts.

There are no obvious issues during single-machine development, but after deploying two or more BFF instances, each instance calculates its own quota. For example, if the limit is 120 requests per minute, two machines might actually allow 240 requests.

docker-compose.yml already has Redis, which can be used as a shared counting base.

Desired Functionality

Replace the current single-machine rate limiting with a Redis-backed rate limiter, supporting the following dimensions:

  • userId
  • tenantId
  • IP
  • agentId
  • toolName
  • modelName

Each dimension should be independently configurable:

  • window
  • request limit
  • key prefix
  • Enable/Disable

When the limit is exceeded, BFF should return:

HTTP/1.1 429 Too Many Requests
Retry-After: 18
Frontend should display an understandable wait time, not just a generic error.

Example Scenario
Settings:
user limit: 120 requests/minute
model limit: 30 requests/minute
User A has reached their model quota, but user B is using a different model.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions