Skip to main content
Course/Module 10/Topic 1 of 4Advanced

SignalR Fundamentals

Understand how SignalR enables real-time bidirectional communication between server and clients without polling — the foundation for chat, notifications, and live updates.

55 minBy Priygop TeamLast updated: Feb 2026

What is SignalR?

ASP.NET Core SignalR is a library that simplifies adding real-time web functionality to applications. In traditional HTTP, the client makes a request and the server responds — the server can't initiate communication to the client. SignalR solves this by maintaining a persistent connection between server and client. It automatically negotiates the best transport: WebSocket (preferred — full-duplex, lowest latency), Server-Sent Events (SSE — server-to-client only, good fallback), and Long Polling (last resort — HTTP-based, works everywhere). SignalR abstracts away transport complexity — you write the same code regardless of which transport is used. It handles connection management, reconnection, message serialization (JSON or MessagePack), and group management. Common use cases: real-time chat, live notifications, collaborative editing, live dashboards, game servers, stock tickers, and IoT data streaming.

Hubs & Communication Patterns

  • Hubs: Server-side classes that handle client connections and messages — clients call hub methods, hubs call client methods. The central abstraction
  • Client-to-Server: Client invokes hub method — connection.invoke('SendMessage', user, message). Hub receives and processes the call
  • Server-to-Client: Hub calls client method — Clients.All.SendAsync('ReceiveMessage', user, message). Client has a registered handler
  • Groups: Organize connections logically — add connections to groups like 'room-1', 'user-123-notifications'. Send messages to specific groups
  • User-based: Send to a specific user (by authentication identity) regardless of how many connections they have — Clients.User(userId).SendAsync()
  • Streaming: Server streams data to clients (IAsyncEnumerable) or clients stream to server — perfect for progress bars, live data feeds

SignalR Architecture Considerations

  • Scaling: SignalR connections are sticky — use Azure SignalR Service or Redis backplane for multi-instance deployments. Azure SignalR handles 1M+ concurrent connections
  • Authentication: SignalR hubs support ASP.NET Core authentication — JWT tokens via query string for WebSocket (headers not supported), cookies for browser clients
  • MessagePack: Binary protocol — 2-5x smaller than JSON, faster serialization. Use for high-throughput scenarios (gaming, IoT, financial data)
  • Connection Lifetime: Handle OnConnectedAsync and OnDisconnectedAsync — track online users, clean up resources, update presence status
  • Error Handling: Use HubException for expected errors — propagates to client. Unhandled exceptions close the connection to prevent data leaks
  • Rate Limiting: Implement per-connection message rate limiting — prevent abusive clients from overwhelming the hub
Chat on WhatsApp
Priygop - Leading Professional Development Platform | Expert Courses & Interview Prep