Course contentsShow
← C#
Lesson 1486 of 1,90813. Real-time Communication with SignalRFree lesson

Designing for High Availability

Deploy redundant SignalR server clusters to ensure continuous message delivery.

In this lesson, you will learn how to architect redundant SignalR server clusters to eliminate single points of failure and ensure seamless message delivery.

The Problem: State Isolation

In a standard SignalR setup, a client maintains a persistent connection to a specific server instance. If that server restarts or crashes, the client loses its connection. More importantly, if you have two servers behind a load balancer, Server A has no idea who is connected to Server B. If a broadcast message originates on Server A, users connected to Server B will never receive it.

The Solution: Backplane Synchronization

To achieve High Availability, you must decouple the connection management from the message distribution. We do this by introducing a Backplane—a shared message bus that acts as a central nervous system for your cluster.

When a hub method on Server A sends a message, it doesn't just push it to local connections; it publishes the message to the backplane. Every other server in the cluster is subscribed to this backplane. When Server B receives the message via the backplane, it re-broadcasts that message to all clients connected locally to it.

Implementation Concept

In ASP.NET Core, you typically implement this using the AddStackExchangeRedis extension. By pointing all instances to the same Redis cluster, you ensure that your SignalR state is shared across your entire fleet:

// Configure the backplane in Program.cs
builder.Services.AddSignalR()
    .AddStackExchangeRedis("your_redis_connection_string", options => {
        options.Configuration.ChannelPrefix = "myapp_signalr";
    });

By leveraging Redis as a backplane, you transform your servers from isolated islands into a unified cluster. If an instance under high load triggers garbage collection or a graceful shutdown, your load balancer can reroute the client to another healthy node. Because the cluster shares the backplane, the client—upon reconnecting—will resume its state and continue receiving messages seamlessly, maintaining high availability without data loss.

Key Takeaway: To achieve high availability in SignalR, you must implement a shared backplane to synchronize message broadcasting across your server cluster, ensuring that clients receive updates regardless of which specific server instance they are currently connected to.