Skip to content

Backend: Add Redis-backed adaptive throttle state for horizontal scaling #862

Description

@Junirezz

Context

adaptiveThrottle.ts penalizes IPs that generate repeated 4xx responses using a decaying abuse score stored per IP.

Problem / Gap

Abuse state is held in a process-local Map. Attackers can evade throttling by hitting different pods, and legitimate blocks do not propagate across instances.

Proposed approach

  • Add a Redis-backed abuse store when REDIS_URL is configured, matching the rate limiter fallback pattern.
  • Keep in-memory store for local/test environments.
  • Expose throttle block count and active blocks in metrics for observability.

Acceptance criteria

  • When Redis is configured, a blocked IP is throttled on all backend instances.
  • When Redis is absent, behavior matches current in-memory implementation with a startup warning.
  • Score decay and block duration logic unchanged from current middleware.
  • Tests cover cross-instance block propagation with a Redis test double or container.

Files/areas affected

  • backend/src/middleware/adaptiveThrottle.ts
  • backend/src/rateLimiter.ts (shared Redis client patterns)
  • backend/src/metrics.ts

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions