Scaling ASP.NET Core SignalR Apps on Heroku
Last updated June 16, 2025
Table of Contents
Deploying ASP.NET Core SignalR applications on Heroku requires minimal setup. However, scaling SignalR apps to multiple dynos requires you to configure:
- Connection Routing: Keep client connections stable in Heroku’s stateless routing environment.
- Message Coordination: Share messages across dynos to reach all connected clients.
Connection Routing
By default, SignalR clients connect through a transport negotiation process that involves multiple HTTP requests. Heroku’s router is stateless by default, so each request can go to any available web dyno. Client connections can break when a request reaches a dyno that doesn’t have the client’s session state from previous requests.
You can resolve this issue with WebSockets (recommended) or Session Affinity.
Manage Connection Routing With WebSockets
We recommend you use WebSockets as it’s the most reliable solution for both clients and servers. WebSockets eliminate transport negotiation and work well with Heroku’s stateless router. To learn more, see WebSockets on Heroku.
Using WebSockets means you lose SignalR’s automatic transport fallback. However, because all modern browsers and clients support WebSockets, we recommend it as it’s often the most reliable approach.
Client Configuration: Skip Transport Negotiation in Your Client Code
const connection = new signalR.HubConnectionBuilder()
.withUrl("/noteHub", {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets
})
.build();
Server Configuration: Enforce WebSocket-Only connections
app.MapHub<YourApp.NoteHub>("/noteHub", options =>
{
options.Transports =
Microsoft.AspNetCore.Http.Connections.HttpTransportType.WebSockets;
});
Manage Connection Routing With Session Affinity
Without WebSockets, SignalR uses HTTP-based transports like Long Polling. Long Polling requires multiple requests to maintain a real-time connection.
If you need to support clients that can’t use WebSockets, you can use Heroku’s session affinity feature. Session affinity is only available for apps on the Common Runtime. To learn more, see Session Affinity.
To enable session affinity, run:
$ heroku features:enable http-session-affinity
Message Coordination
In a multi-dyno environment, you also need a backplane to share messages between servers. Setting up a backplane ensures messages from any dyno reach all relevant clients.
To learn more about scaling with backplanes, see Microsoft’s SignalR Scaling documentation.
Set Up a Redis Backplane
You can set up a Redis backplane with the Heroku Key-Value Store add-on:
Add the Heroku Key-Value Store add-on:
$ heroku addons:create heroku-redis:mini
Install the SignalR Redis package:
$ dotnet add package Microsoft.AspNetCore.SignalR.StackExchangeRedis
Configure the backplane for SignalR:
// Program.cs // ... using StackExchange.Redis; var builder = WebApplication.CreateBuilder(args); var redisUrl = Environment.GetEnvironmentVariable("REDIS_URL"); if (!string.IsNullOrEmpty(redisUrl)) { // Parse the Redis URL for our client var uri = new Uri(redisUrl); var userInfoParts = uri.UserInfo.Split(':'); if (userInfoParts.Length != 2) { throw new InvalidOperationException("REDIS_URL is not in the expected format ('redis://user:password@host:port')"); } var configurationOptions = new ConfigurationOptions { EndPoints = { { uri.Host, uri.Port } }, Password = userInfoParts[1], Ssl = true, }; // Handle Heroku's self-signed certificates // See: https://devcenter.heroku.com/articles/heroku-redis#security-and-compliance configurationOptions.CertificateValidation += (sender, cert, chain, errors) => true; // Set up the SignalR backplane builder.Services.AddSignalR().AddStackExchangeRedis(options => { options.Configuration = configurationOptions; options.Configuration.ChannelPrefix = "YourAppName"; }); } else { // Local development fallback builder.Services.AddSignalR(); } var app = builder.Build(); // ... app.Run();
To learn more about connecting your .NET app, see our Heroku Key-Value Store docs.
Summary
To successfully scale a SignalR app on Heroku:
Single dyno: No special configuration needed.
Multiple dynos require:
- A WebSockets-only configuration on both client and server (recommended) or Session Affinity.
- A Redis backplane configured with Heroku Key-Value Store.