JustBet Stream Service
Application Overview
The Stream service is a real-time data streaming and WebSocket management service for the JustBet platform. Built with Socket.IO and Redis adapter, it provides real-time game events, price feeds, and multiplayer game state updates to connected clients. The service handles WebSocket connections efficiently and ensures reliable real-time communication between the platform and users.
End Users
- Active game players
- Platform users watching live games
- Third-party applications consuming real-time data
- Platform monitoring systems
Critical Features
- Real-time Game Event Streaming Live game results and updates Multiplayer game state synchronization Event decoding and broadcasting Chain-specific event rooms
- Price Feed Integration Real-time cryptocurrency price updates Pyth Network integration Multi-chain price monitoring Price feed broadcasting
- WebSocket Management Efficient connection handling Redis-based socket clustering Room-based event broadcasting Automatic reconnection handling Problems Solved Real-time data synchronization across multiple clients Scalable WebSocket connections management Cross-chain event monitoring and broadcasting High-frequency price feed distribution Multiplayer game state consistency Workflow Improvements Reduced latency in game updates Efficient resource usage through Redis adapter Improved reliability with automatic reconnection Better monitoring with telemetry integration Simplified client-side integration WebSocket Namespaces JustBet Events // Namespace: /justbet/stream // Events:
- 'event': Game event updates
- 'connection': New client connection
- 'disconnect': Client disconnection Price Feeds // Namespace: /common/price-feeds // Events:
- 'price': Real-time price updates
- 'connection': Price feed subscription
- 'disconnect': Price feed unsubscription Multiplayer Games // Namespace: /justbet/multiplayer // Events:
- 'game-state': Current game state
- 'player-action': Player moves/actions
- 'game-result': Game round results WebSocket Client Integration Connecting to Game Events
import { io } from 'socket.io-client';
const socket = io('ws://localhost:3000/justbet/stream', {
const socket = io('ws://localhost:3000/justbet/stream', {
transports: ['websocket'],
query: { chain: 'ethereum' }
});
socket.on('event', (data) => {
console.log('Received game event:', data);
});Subscribing to Price Feeds
const priceSocket = io('ws://localhost:3000/common/price-feeds', {
transports: ['websocket']
});
priceSocket.on('price', (data) => {
console.log('Received price update:', data);
});Architecture Notes
- Uses Redis adapter for horizontal scaling
- Implements room-based event broadcasting
- Supports multiple chain configurations
- Integrates with OpenTelemetry for monitoring
- Uses Pino for structured logging