Building Real-Time Features
Build production-ready real-time features — chat systems, live notifications, collaborative editing, and live dashboards with best practices.
55 min•By Priygop Team•Last updated: Feb 2026
Chat System Architecture
- Message Hub: Central hub handling SendMessage, JoinRoom, LeaveRoom, TypingIndicator — route messages to correct groups
- Message Persistence: Save messages to database (EF Core) — load history on connection. Don't rely on SignalR for message storage
- Typing Indicators: Client sends 'typing' events with debouncing (300ms) — hub broadcasts to room group, client shows 'user is typing...'
- Read Receipts: Track last-read message per user per conversation — client sends 'MarkRead' events, display read counts/checkmarks
- File Sharing: Upload files via regular HTTP POST (not SignalR — binary over WebSocket is inefficient), send file URL as chat message
- Presence: Track online/offline status using OnConnected/OnDisconnected — broadcast presence changes to relevant groups/contacts
Live Dashboard & Notifications
- Dashboard Updates: Server pushes data changes to connected clients — stock prices, metrics, order counts. Use typed hub clients for type safety
- Push Notifications: Combine SignalR (real-time in-app) with web push notifications (when app is closed) and email (for important, missed notifications)
- Event Aggregation: Batch rapid updates — instead of 100 individual stock updates per second, aggregate into a single batch update every 250ms
- Reconnection Strategy: Client-side automatic reconnection with exponential backoff — .withAutomaticReconnect([0, 2000, 5000, 10000, 30000])
- Offline Queue: Queue messages while disconnected, replay on reconnection — ensures no data loss during network interruptions
- Load Testing: Test with thousands of concurrent connections — use k6 with WebSocket support or custom SignalR load test tools