Overview & Background
FlowFi delivers real-time stream status and balance updates to connected web clients via Server-Sent Events (SSE) implemented in backend/src/services/sse.service.ts.
Currently, SSEService stores client connections in an in-memory Set<Response>. In a production deployment with multiple backend instances behind a load balancer (e.g. Render, AWS ECS, or Kubernetes), an event processed by the indexer on Instance A is only broadcast to clients connected to Instance A. Clients connected to Instance B miss the live update.
Detailed Problem Statement
- Multi-container scaling breaks real-time updates for frontend users.
- Without a shared pub/sub message bus, horizontal scaling of backend API instances is impossible.
Technical Specification & Architecture
1. Redis Pub/Sub Architecture
[Soroban Indexer]
│
▼
[Publish: flowfi:stream-events] ──► (Redis Cluster)
│
┌───────────────────────┴───────────────────────┐
▼ ▼
[Backend Node A] [Backend Node B]
│ │
[Local SSE Clients] [Local SSE Clients]
2. Implementation in backend/src/services/sse.service.ts
- Import Redis publisher and subscriber clients from
backend/src/lib/redis.ts.
- When
sseService.broadcast(event) is called:
- Serialize event payload to JSON.
- Publish to channel
flowfi:events:broadcast.
- In subscriber initialization:
- Subscribe to
flowfi:events:broadcast.
- On incoming message, parse payload and dispatch to local
clients Set.
- Resilience & Fallback:
- If Redis is disconnected or unconfigured in development (
REDIS_ENABLED=false), gracefully fall back to local in-memory broadcasting.
Target Files
backend/src/services/sse.service.ts
backend/src/lib/redis.ts
backend/src/controllers/sse.controller.ts
backend/tests/unit/sse.service.test.ts
Acceptance Criteria
Overview & Background
FlowFi delivers real-time stream status and balance updates to connected web clients via Server-Sent Events (SSE) implemented in
backend/src/services/sse.service.ts.Currently,
SSEServicestores client connections in an in-memorySet<Response>. In a production deployment with multiple backend instances behind a load balancer (e.g. Render, AWS ECS, or Kubernetes), an event processed by the indexer on Instance A is only broadcast to clients connected to Instance A. Clients connected to Instance B miss the live update.Detailed Problem Statement
Technical Specification & Architecture
1. Redis Pub/Sub Architecture
2. Implementation in
backend/src/services/sse.service.tsbackend/src/lib/redis.ts.sseService.broadcast(event)is called:flowfi:events:broadcast.flowfi:events:broadcast.clientsSet.REDIS_ENABLED=false), gracefully fall back to local in-memory broadcasting.Target Files
backend/src/services/sse.service.tsbackend/src/lib/redis.tsbackend/src/controllers/sse.controller.tsbackend/tests/unit/sse.service.test.tsAcceptance Criteria