Skip to content

[PERF] Add Redis connection pooling for high-throughput public API endpoints to reduce connection overhead #278

@Abhushan187

Description

@Abhushan187

Problem

The public API currently creates a new Redis connection per request for rate limiting, lockout checks, and caching. Under high load (1000+ concurrent requests), this causes connection exhaustion, increased latency, and potential Redis ECONNREFUSED errors. The existing ioredis or redis client is likely instantiated without pooling.


Proposed Improvement

Implement a Redis connection pool for all public API endpoints that interact with Redis (rate limiting, lockout, caching, analytics). The feature should:

  • Use a single shared Redis connection pool (max 20 connections, min 5) across the public API
  • Apply pooling to checkLockout, recordFailedAttempt, clearLockout, and analytics counters
  • Add connection health checks and automatic reconnection with jittered backoff
  • Expose pool metrics (active connections, wait queue size, total commands) via GET /api/health/redis
  • Reduce P99 latency for auth endpoints by eliminating per-request connection overhead

Expected Impact

  • Better performance under high concurrency
  • Reduced Redis server load and connection count
  • Improved reliability with connection health monitoring
  • Better long-term scalability for production deployments

Possible Implementation

  • Add RedisPool class in packages/common/redis/ using ioredis cluster mode or generic-pool
  • Refactor apps/public-api/middleware/rateLimiter.js to use pooled connections
  • Refactor apps/public-api/services/lockout.js (checkLockout/recordFailedAttempt/clearLockout)
  • Add redisPoolMetrics middleware exposing pool stats
  • Update docker-compose.yml to include Redis with maxclients config
  • Write load tests using autocannon or k6 to verify latency improvement
  • Add resilience tests for pool exhaustion and connection failure scenarios

I'm GSSoC'26 contributor, Please assign this task to me!

Metadata

Metadata

Assignees

Labels

No labels
No labels

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