GUIDE

What is SignalR?

What is SignalR?.jpg

What is SignalR?

SignalR is an open-source, real-time messaging framework developed by Microsoft that allows developers to build interactive and dynamic applications that instantly push data between servers and connected clients.  SignalR provides a seamless and efficient way for developers to build real-time functionality, such as chat applications, collaboration tools, IoT device control, or real-time dashboards, providing an API that handles the underlying plumbing and simplifies the task of implementing real-time communication.

What are the Features of SignalR?

Real-time communication:

SignalR allows instant, bidirectional communication between the server and the client, such as web browsers, mobile devices, and desktop applications. In addition to point-to-point communication, SignalR allows developers to broadcast messages to multiple clients or specific groups of clients, useful for scenarios like chat rooms or push notifications.

It can seamlessly handle numerous concurrent connections distributed across multiple server instances by supporting configurable backplane implementations like SQL Server, Redis, and Azure Service Bus.

Platform support:

SignalR is primarily designed for use with .NET applications, and its language support reflects this.  The supported programming languages are .NET (NET 6 and NET 7), .NET Core, Java, and JavaScript

Client / Server connection:

SignalR maintains a persistent connection between the client and the server, enabling real-time updates with low network overhead and enterprise-grade performance.  The protocol provides automatic reconnection capabilities, allowing clients to reconnect to the server in case of network interruptions or server restarts, ensuring a seamless user experience even in unstable network conditions.

Architecture:

SignalR is based on a client-server architecture and follows a hub-and-spoke pattern.  The SignalR server manages connections, routes messages between clients, and handles client connection/disconnection events.  Clients (e.g., a web browser or mobile app) are responsible for connecting to the SignalR server and sending/receiving messages.  

Hubs are the main communication channels, abstracting the underlying transport layer and providing a high-level API for clients.  Hubs can be thought of as remote procedure call (RPC) endpoints that clients can invoke, and they can also broadcast messages to multiple clients. 

ASP.NET Identity and other authentication providers are supported, enabling authentication at the connection or individual method levels.

SignalR offers two main hosting modes: Self-hosting and the Azure SignalR Service. The former gives developers full control over their hosting, but they are responsible for managing and configuring the environment, including how the solution will scale. Azure SignalR Service is a fully managed service provided by Microsoft, which abstracts away scaling and availability concerns so the developer can focus on application logic.

Customization and Extensibility:

SignalR is highly extensible and allows developers to customize and extend its functionality. It provides hooks for customizing connection management, message serialization, and other aspects of the communication process.  SignalR also provides flexible error handling, allowing developers to implement the appropriate logging or recovery mechanisms.

SignalR Limitations

SignalR is a very powerful and configurable messaging solution that offers many developer benefits. Still, it can be complex to set up and configure and may involve configuring server infrastructure to support real-time communication.  The learning curve for developers new to real-time communication or the SignalR library can be steep, especially in mastering the APIs and understanding the best practices to create a performant and scalable solution for applications that will handle very high traffic.

SignalR requires developers to manage the infrastructure, including servers and network resources. This can be time-consuming and costly, monitoring and maintaining server health, ensuring sufficient bandwidth for message delivery, and handling potential scaling needs.

It is primarily designed for use with .NET applications and is limited in its compatibility with other platforms and frameworks. While libraries and plugins are available for other languages, the level of support and functionality may vary, presenting developers unfamiliar with the .NET ecosystem with an additional learning curve.

Comparing SignalR with PubNub

Both PubNub and SignalR are popular platforms for building real-time solutions, including chat and messaging applications. While the two have many similarities, including abstracting the underlying protocol away from the developer, they also have key differences, so developers should consider carefully when choosing between them.

One key difference is in the architecture between the two solutions:

SignalR PubNub HLA Comparison

Diagram comparing the high-level architecture of SignalR (left) with PubNub (right)

SignalR is deployed to servers you are responsible for (or managed with the SignalR Azure Service), and you need to ensure that the solution will scale appropriately. You then implement the required messaging routing logic using the flexible and powerful SignalR API. Clients send and receive messages using the appropriate .NET, Java, or JavaScript API.

PubNub is a managed and hosted solution that will scale automatically as your solution grows. Message routing is handled through PubNub’s flexible channel mechanism, and messages are exchanged with clients using any of the 50+ platform SDKs supported.  PubNub also supports Functions, allowing applications to integrate custom message logic (such as translation or sentiment analysis) without worrying about scaling or deployment concerns.

Customers looking for a solution to host themselves, either on-prem or on-cloud, and have a strong background with .NET or specific message routing requirements should consider SignalR.  Be sure to plan for the ongoing maintenance costs associated with any self-hosted solution at scale.

For most customers, PubNub will be the better choice when developing any real-time solution. It is a ready-made solution that scales automatically, globally, and infinitely without hosting anything yourself. PubNub provides a simple but flexible message routing mechanism through its channel concept, which can be extended using PubNub Functions to intercept and modify messages as required. PubNub supports far more client front-ends; for example, SignalR requires mobile device clients to use Xamarin/Maui, whereas PubNub supports native Android/iOS development and around 50 other SDKs.

If you want to learn more about PubNub or decide between a SignalR vs. PubNub deployment, please contact our dedicated support team or email our developer relations team at devrel@pubnub.com.