Summary
The backend currently runs as a single instance. For horizontal scaling (multiple backend instances behind a load balancer), we need Redis pub/sub to synchronize WebSocket state, cache invalidation, and task scheduling across instances.
Current State
- WebSocket gateway (
src/websocket/gateway.ts) tracks agent connections in an in-memory CappedMap
- Agent registry is in-process — only the instance that received the agent handshake can route commands to that agent
- Task scheduler runs in-process — only one instance should schedule tasks to avoid duplicate execution
- Permission caching uses in-memory 30-second TTL — no cross-instance invalidation
- Redis is already in the Docker Compose stack but only used for future pub/sub (not currently connected)
catalyst-backend/package.json does not include ioredis or any Redis client yet
Requirements
- Add Redis client (
ioredis) to backend dependencies
- Agent registry: publish agent connection/disconnection events via Redis pub/sub so all instances know which agent is connected where
- WebSocket routing: when a client request needs to reach an agent on a different instance, forward the command via Redis pub/sub
- Task scheduling: use Redis-based distributed lock (e.g.,
Redlock) so only one instance runs scheduled tasks at a time
- Cache invalidation: broadcast permission/config cache invalidation across instances via Redis pub/sub
- Session affinity: document that WebSocket connections require sticky sessions or that the pub/sub bridge handles cross-instance routing transparently
Acceptance Criteria
Summary
The backend currently runs as a single instance. For horizontal scaling (multiple backend instances behind a load balancer), we need Redis pub/sub to synchronize WebSocket state, cache invalidation, and task scheduling across instances.
Current State
src/websocket/gateway.ts) tracks agent connections in an in-memoryCappedMapcatalyst-backend/package.jsondoes not includeioredisor any Redis client yetRequirements
ioredis) to backend dependenciesRedlock) so only one instance runs scheduled tasks at a timeAcceptance Criteria