Covers scaling ASP.NET Core SignalR horizontally: why connections and groups are per server, sticky sessions and when they are needed, the Redis backplane, Azure SignalR Service (default and serverless modes, units), connection and message limits, and capacity planning.
A SignalR server only knows its own connections and groups, held in memory. Scale out to several instances and Clients.Group("x") on server A never reaches users connected to server B. Self-hosted, you also need sticky sessions, because the negotiate request and the SSE or long-polling requests must reach the same server (WebSockets-only with SkipNegotiation avoids that). Affinity costs you even load distribution, and clients on a failed instance must reconnect. The Redis backplane fixes delivery by publishing every message to every server. It works well at moderate scale, but every server processes every message, and pub/sub doesn't buffer during a Redis failover, so run Redis highly available. Azure SignalR Service moves the client connections off your app: your servers keep a handful of connections to the service, which handles fan-out, at about 1,000 concurrent connections per Standard unit.
For 100,000 connections, I would use Azure SignalR Service, plan units from peak connections and fan-out, and design for reconnect storms.
"The root cause is that SignalR state is per process. The default
HubLifetimeManagerkeeps connection ids and group memberships in memory, so with four instances each knows about a quarter of the users. Two things break. Messages sent to a group or user only reach the local connections, which is the 'some users don't get messages' symptom. And if a client falls back to SSE or long polling, its negotiate call and its later requests may land on different instances, which gives a 404 on the connection id and the 'stuck reconnecting' symptom. That second one is why self-hosted SignalR needs sticky sessions unless every client is WebSockets-only with negotiation skipped.For example, at [company] we had [a dispatch dashboard] on [three App Service instances]. We first added the Redis backplane: one line,
AddStackExchangeRedis, and every message is published to a Redis channel that all servers subscribe to. That fixed delivery, but every server now processes every message, so fan-out cost grows with instance count, and Redis became a single point of failure. When we grew to about [40,000] connections we moved to Azure SignalR Service. The app connects to the service with a few server connections, clients are redirected there by negotiate, and we no longer needed ARR affinity. [Deployment disconnects dropped to near zero and we cut instance count from X to Y.]For 100,000 concurrent connections I would design around three numbers: peak concurrent connections, messages per second multiplied by average fan-out, and the reconnect rate during deployments. On Azure SignalR Standard that is roughly 100 units for connections, then I would check the message quota. The mistake I see is sizing by HTTP requests per second. With SignalR you size by connections and fan-out."
| Option | How it works | Sticky sessions? | Limits and risks |
|---|---|---|---|
| Single server | All state in memory | No | One instance's sockets and memory; no redundancy |
| Redis backplane | Every server publishes to Redis pub/sub; all servers receive every message | Yes, unless WebSockets-only with SkipNegotiation |
Every server processes every message; Redis throughput and availability; pub/sub is fire-and-forget |
| Azure SignalR Service (default mode) | Clients connect to the service; your hubs still run in your app over server connections | No (the service handles routing) | Billed per unit; about 1,000 concurrent connections per Standard unit; message quotas |
| Azure SignalR Service (serverless) | No hub server; Azure Functions or REST API push messages | No | No hub methods in your app; upstream webhooks for client messages |
| Orleans or custom fan-out | Your own routing layer | Depends | Only when you have very specific needs |
| Factor | Question to answer | Example |
|---|---|---|
| Concurrent connections | Peak, not daily average | 100k at the 8:30 am peak → ~100 Standard units, or Premium |
| Fan-out | Messages per second times recipients | 50 broadcasts/s to 2,000-user groups = 100k deliveries/s |
| Message size | Billing counts messages in 2 KB chunks | Trim payloads; send ids and let clients fetch details |
| Reconnect storm | What happens when 100k clients reconnect in 10 s? | Jittered withAutomaticReconnect delays, staggered rollouts |
| Region | Users in Australia | Azure SignalR in Australia East with the app in the same region |
Moving a [dispatch] dashboard from a Redis backplane on [four] instances to Azure SignalR Service removed ARR affinity and let us scale the app on CPU instead of connections. Instance count dropped from [8 to 3], and the p95 delivery latency of broadcasts went from [about 900 ms to under 200 ms] because servers no longer processed every message.
Checks whether the candidate understands why SignalR state is per server, can explain sticky sessions and backplanes precisely, and can size a large deployment by connections and fan-out.
Green flags
Red flags
Load balancer (round robin)
/ \
Server A Server B
connections: u1, u2 connections: u3, u4
group "vic": u1 group "vic": u3
Server A: Clients.Group("vic").Send(...) -> only u1 receives it. u3 never does.
The default DefaultHubLifetimeManager<THub> stores everything in local dictionaries. Nothing is shared.
Negotiate creates a connection id on one server. With WebSockets, the next request upgrades and stays on one TCP connection, so it's fine if negotiate and the upgrade reach the same server. With SSE, every client-to-server message is a separate POST, and with long polling every poll is a new request. Those must all reach the server that owns the connection id; otherwise you get 404 No Connection with that ID. Hence ARR affinity on App Service, sessionAffinity cookies on ingress, or WebSockets-only with skipNegotiation: true.
Server A --PUBLISH "hub:group:vic"--> Redis <--SUBSCRIBE-- Server B, Server C, Server D
RedisHubLifetimeManager turns every send into a Redis publish, and each server delivers to its local members. Consequences:
ChannelPrefix if several apps share one.browser --negotiate--> your app --returns service URL + access token--> browser
browser ==WebSocket==> Azure SignalR Service <==server connections (5 per hub per server by default)== your app
Your hub code doesn't change: AddSignalR().AddAzureSignalR(). The service multiplexes thousands of client connections over a few server connections, routes group and user messages itself, and handles the client sockets. In serverless mode there is no hub server: you push through the REST API or Azure Functions bindings.
Units: in the Standard tier, one unit gives about 1,000 concurrent connections and a daily message quota, and you can scale up to 100 units per instance (Premium adds autoscale and higher limits). Check current limits in the Azure docs, because they change.
When an instance stops, every client connected to it reconnects at once. With 25,000 clients per instance, that is 25,000 negotiate requests, token validations and group re-joins in a few seconds. Mitigations: jittered retry delays in withAutomaticReconnect([0, 2000, 10000, 30000]) plus random offsets, rolling deployments with maxSurge, and with Azure SignalR Service, graceful shutdown (GracefulShutdown.Mode = MigrateClients) to move clients to other servers.
ip_hash and see them stop.MONITOR in redis-cli.crankier (the SignalR load tool in the aspnetcore repo) or k6's WebSocket support to open 20,000 connections and record memory per connection with dotnet-counters.The same hub, three ways to host it. Hub code doesn't change; only registration does.
// Program.cs (.NET 10)
using Microsoft.AspNetCore.SignalR;
var builder = WebApplication.CreateBuilder(args);
var signalR = builder.Services.AddSignalR();
switch (builder.Configuration["SignalR:Mode"])
{
case "Redis":
// Every server publishes every message to Redis; all servers deliver to local members.
// Still needs sticky sessions unless every client is WebSockets-only.
signalR.AddStackExchangeRedis(builder.Configuration.GetConnectionString("SignalRRedis")!, o =>
o.Configuration.ChannelPrefix = StackExchange.Redis.RedisChannel.Literal("dispatch"));
break;
case "Azure":
// Clients connect to Azure SignalR Service; the app keeps a few server connections.
// Connection string comes from Key Vault or managed identity config, never appsettings.json.
signalR.AddAzureSignalR(o =>
{
o.ConnectionString = builder.Configuration["Azure:SignalR:ConnectionString"];
o.GracefulShutdown.Mode = Microsoft.Azure.SignalR.GracefulShutdownMode.MigrateClients;
o.GracefulShutdown.Timeout = TimeSpan.FromSeconds(20);
});
break;
}
var app = builder.Build();
app.MapHub<DispatchHub>("/hubs/dispatch");
app.Run();
public interface IDispatchClient
{
Task JobUpdated(JobUpdate update);
}
public sealed record JobUpdate(int JobId, string Status); // ids and status only: keep messages small
public sealed class DispatchHub : Hub<IDispatchClient>
{
public override async Task OnConnectedAsync()
{
// Re-join groups on every (re)connect: membership is not persisted.
if (Context.User?.FindFirst("depot")?.Value is { } depot)
await Groups.AddToGroupAsync(Context.ConnectionId, $"depot-{depot}");
await base.OnConnectedAsync();
}
}
// Client: jittered reconnect so 25,000 clients don't all retry at the same millisecond.
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hubs/dispatch", { accessTokenFactory: getToken })
.withAutomaticReconnect({
nextRetryDelayInMilliseconds: ctx =>
ctx.elapsedMilliseconds > 120000 ? null : Math.min(30000, 1000 * 2 ** ctx.previousRetryCount) + Math.random() * 3000
})
.build();
# Kubernetes ingress-nginx: cookie affinity for a self-hosted Redis-backplane setup
metadata:
annotations:
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "signalr-affinity"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
SkipNegotiation, or use Azure SignalR Service.Self-hosting with a Redis backplane is fine up to a few thousand connections per instance and modest fan-out, provided Redis is replicated and monitored. Beyond that, Azure SignalR Service usually wins on total cost of ownership: you stop scaling your app for sockets and scale it for CPU, and sticky sessions disappear. The service has its own limits (units, message quotas, a cap per instance) and its bill includes units, messages beyond the quota and outbound data transfer, so put the numbers in a spreadsheet, not just the architecture diagram.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Single instance | Internal tools, under ~5k connections, downtime acceptable | Cheapest | Anything needing redundancy |
| Redis backplane | A few instances, modest fan-out, data must stay in your network | HA Redis plus sticky sessions and uneven load | High fan-out across many instances |
| Azure SignalR Service | Tens of thousands of connections, Azure-hosted, want no affinity | Units per day, extra messages, egress | Strict on-premises requirements, or no Azure |
| Serverless SignalR | Push-only notifications from Functions | Pay per unit, no hub server | You need hub methods with app logic |
| Sticky sessions | Benefit | Cost |
|---|---|---|
| On (self-hosted) | Works with every transport | Uneven load after scale-out, mass reconnect when an instance fails, harder blue-green deployments |
| Off (WebSockets-only or Azure SignalR) | Even load, stateless app tier | Clients behind proxies that block WebSockets can't connect when self-hosted |
Also ask whether you need SignalR at all for the hot path. Broadcasting a price feed to 100,000 read-only viewers may be cheaper as SSE through a CDN or Azure Web PubSub. Keep SignalR where you need two-way interaction.
SignalR is ASP.NET Core's real-time framework. A hub is a class whose public methods clients call, and the server calls methods on clients through Clients.All, Clients.Group(...) or Clients.User(...). Hubs are transient, created per invocation, so they hold no state. On connect the client calls negotiate and uses the best transport available: WebSockets, then Server-Sent Events, then long polling. Groups fan messages out to subsets of connections, but they live in memory, so a reconnecting client must re-join them (usually in OnConnectedAsync). Strongly typed hubs (Hub<IOrderClient>) replace method-name strings with an interface. Authentication uses the normal pipeline with [Authorize]. Browsers can't send an Authorization header on WebSockets or EventSource, so as a workaround the token travels as an access_token query parameter, read in JwtBearerEvents.OnMessageReceived.
The trade-off: reconnects and routing come free, but every client holds a stateful connection that you must plan to scale.
A load balancer spreads traffic across healthy instances.
Health checks remove unhealthy instances (in Kubernetes: readiness for traffic, liveness for restarts). Algorithms: round robin, least connections/requests, hashing. Sticky sessions pin a user to one instance, which hurts scaling and failover. Connection draining stops new traffic to an instance before shutdown so in-flight requests finish.
gRPC uses long-lived HTTP/2 connections, so an L4 balancer balances connections, not calls: one client connection carries all its calls to one pod. Use L7 balancing (mesh/Envoy) or client-side load balancing.
A burst of 502s on every rollout is almost always a shutdown or start-up race, not a code bug. On termination, Kubernetes sends SIGTERM to the container and removes the pod from the Service endpoints at the same time, so the ingress keeps sending requests for a few seconds to a process that is closing. I fix it in layers, with numbers that must add up: a preStop sleep (about 10 s) so routing updates first; HostOptions.ShutdownTimeout sized from the measured p99.9 request duration (say 15 s) so in-flight requests drain; and terminationGracePeriodSeconds larger than both together (35 s). Then readiness probes that only pass when the app is warm and fail once ApplicationStopping fires, separate from liveness, plus maxUnavailable: 0. I also check keep-alive timeouts: if Kestrel closes idle connections before the proxy does, the proxy reuses a dead connection and returns 502. The trade-off is slightly slower deployments for zero dropped requests.
How to tell it (STAR)
**S:** Our [dispatch] app pushed job updates to about [12,000] browsers. When we scaled from one to four instances for [the seasonal peak], dispatchers started missing jobs and some got stuck reconnecting. **T:** I had to find out why within [a day], because missed jobs meant [late deliveries]. **A:** I grouped the failures by instance in Application Insights and saw negotiate and the follow-up requests on different servers for users who had fallen back from WebSockets. Broadcasts also only reached the sending instance, because we had no backplane. I restored affinity as a stopgap, then moved us to Azure SignalR Service, sized at [15] units from our peak connection count, and added jittered reconnects and graceful client migration. **R:** Missed-update tickets went from [about 30 a day to zero], and we could scale the app on CPU from then on: [instance count and cost numbers].
Last updated 23 Nov 2026.