SignalR

Intro

SignalR is ASP.NET Core's real-time communication framework for bidirectional server/client messaging over persistent connections. It is the default choice when the server must push updates immediately (chat, live dashboards, collaborative workflows, notifications) without polling-heavy architectures. A stock trading dashboard, for example, uses SignalR to push price updates to 50,000 concurrent browser clients with sub-100ms delivery — replacing a 5-second polling interval that was generating 10,000 requests/second and still showing stale prices. SignalR hides transport negotiation details behind hubs, but production success still depends on scaling, connection lifecycle handling, and clear authorization boundaries.

How It Works

Mental Model

sequenceDiagram
  participant Client
  participant Hub as Hub runtime
  participant App as App service

  Client->>Hub: Connect and negotiate transport
  Hub->>App: Invoke hub method
  App->>Hub: Publish event/message
  Hub->>Client: Push update

SignalR negotiates the best available transport (WebSockets first, then fallback options). Hub methods are invoked per call on transient hub instances, and outbound messages are routed through Clients.* targets (All, User, Group, etc.).

Example

Hub:

public sealed class ChatHub : Hub
{
    public async Task Send(string message)
    {
        await Clients.All.SendAsync("message", message);
    }
}

Register in ASP.NET Core pipeline:

builder.Services.AddSignalR();

var app = builder.Build();
app.MapHub<ChatHub>("/hubs/chat");
app.Run();

Pitfalls

Tradeoffs

Questions


Whats next

Parent
NET

Pages