microsoft3 min read

SignalR Tutorial: Learn Real-Time Web from Scratch (2026)

SignalR Tutorial: Learn Real-Time Web from Scratch (2026)

Published:  |  Category: Microsoft  |  Reading time: ~15 min
SignalR Tutorial: Learn Real-Time Web from Scratch (2026)

When I first needed to push live updates from server to browser, I cobbled together a polling mechanism that worked — barely. Then I discovered SignalR, and real-time communication went from duct-tape-and-prayer to an elegant, production-grade solution. I have since used SignalR in trading dashboards, live collaboration tools, and IoT monitoring systems, and it has never let me down.

SignalR is a real-time communication library for .NET that enables server-to-client push notifications, broadcasting, and bidirectional messaging. It handles connection management, reconnection, scaling out with backplanes like Redis or Azure SignalR Service, and falls back gracefully when WebSockets are unavailable.

Setting Up a SignalR Hub

Everything in SignalR revolves around Hubs — a central class that calls methods on connected clients. Define a hub by inheriting from Hub or Hub. The hub handles connection lifecycle and exposes methods clients invoke remotely. Register with AddSignalR and MapHub in Program.cs.

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalR().AddMessagePackProtocol();
var app = builder.Build();
app.MapHub("/hubs/chat");
app.Run();
public class ChatHub : Hub
{
    public async Task SendMessage(string user, string message)
    {
        await Clients.All.SendAsync("ReceiveMessage", user, message);
    }
}

Client-Side Integration in JavaScript and .NET

SignalR provides client SDKs for JavaScript, .NET, Java, and Python. The JavaScript client uses @microsoft/signalr. Create a HubConnectionBuilder, configure URL, enable auto-reconnect, and start. Call server methods with invoke and listen with on.

const connection = new signalR.HubConnectionBuilder()
    .withUrl("/hubs/chat")
    .withAutomaticReconnect([0,2000,10000,30000])
    .build();
connection.on("ReceiveMessage",(u,m)=>console.log(u+": "+m));
await connection.start();
await connection.invoke("SendMessage","Alice","Hello!");

Broadcasting to Groups and Specific Users

SignalR Groups let you add connections to logical buckets — by chat room, tenant, or device type. Use Groups.AddToGroupAsync and Groups.RemoveFromGroupAsync. Messages via Clients.Group reach every connection in that group.

public async Task JoinRoom(string roomName)
{
    await Groups.AddToGroupAsync(Context.ConnectionId, roomName);
    await Clients.Group(roomName).SendAsync("SystemMessage",
        $"{Context.UserIdentifier} joined {roomName}");
}

Scaling Out with a Backplane

Without a backplane, messages stay within one server. Redis backplane uses Pub/Sub to relay across servers. Azure SignalR Service is a managed backplane handling scaling and WebSocket management globally.

builder.Services.AddSignalR()
    .AddStackExchangeRedis("localhost:6379",options=>{
        options.Configuration.ChannelPrefix="SignalR";
    });

Streaming Data from Server to Client

SignalR supports streaming where the server pushes results as they become available. Return a ChannelReader or IAsyncEnumerable. The client subscribes with stream. The framework handles backpressure automatically.

public ChannelReader StreamCounter(int count,int delay)
{
    var channel=Channel.CreateBounded(10);
    _=Task.Run(async()=>{
        for(var i=0;i

Production Hardening: Logging, Errors, and Monitoring

Configure KeepAliveInterval and ClientTimeoutInterval to detect dead connections. The server sends pings; unresponsive clients are disconnected. Monitor with Azure Monitor tracking connections, messages per second, and failed invocations.

builder.Services.AddSignalR(options=>{
    options.KeepAliveInterval=TimeSpan.FromSeconds(15);
    options.ClientTimeoutInterval=TimeSpan.FromSeconds(30);
    options.MaximumReceiveMessageSize=32768;
});
builder.Logging.AddFilter("Microsoft.AspNetCore.SignalR",LogLevel.Warning);

Frequently Asked Questions

What transport protocols does SignalR use?

SignalR negotiates between WebSockets (preferred), Server-Sent Events, and Long Polling. It automatically selects the best transport available on both client and server.

Does SignalR work with Azure Functions?

Yes, Azure Functions supports SignalR bindings via the Azure SignalR Service. Use SignalR output bindings for serverless real-time communication.

How does SignalR handle reconnection?

SignalR clients can be configured with automatic reconnection using configurable delay intervals. The client retries and invokes callbacks on success or exhaustion.

Can SignalR scale to millions of concurrent connections?

Yes. Azure SignalR Service handles millions of concurrent connections with automatic scaling and global distribution.

Originally published on Ayodhyyya. Last updated June 1, 2026.