realtime-service (C4 Level 3)
Ответственность
- WebSocket connections
- Subscribe/unsubscribe topics
- Forward NATS/Redis events to clients
- Heartbeat, reconnect support
Компоненты
flowchart TB
subgraph realtime [realtime-service]
WSGateway[WebSocket Gateway]
ConnMgr[Connection Manager]
TopicSub[Topic Subscription]
EventForwarder[Event Forwarder]
AuthMW[WS Auth Middleware]
end
Web[web-app] --> WSGateway
AuthMW --> WSGateway
WSGateway --> ConnMgr
ConnMgr --> TopicSub
EventForwarder --> ConnMgr
Redis[(Redis PubSub)] --> EventForwarder
NATS[NATS] --> EventForwarder
| Компонент | Описание |
|---|---|
| WebSocket Gateway | Starlette/FastAPI WS endpoint |
| Connection Manager | Map connection_id → topics |
| Topic Subscription | session:{id}, game:{id} |
| Event Forwarder | Filter + serialize to WS JSON |
| WS Auth Middleware | Validate JWT/guest on connect |
Topics
game:{game_id}— state changessession:{session_id}— participant events
Масштабирование
- Sticky sessions или Redis adapter для multi-instance
- Connection count metric в Prometheus
FR/NFR
FR-025, FR-028, NFR-002, NFR-009