Real-Time Apps

Building Real-Time Apps with ASP.NET Core and SignalR: Chat Apps, Live Dashboards & Scalability Tips

In 2025, users expect applications to react instantly — whether it's chatting with teammates, watching live stock updates, tracking delivery, monitoring IoT sensors, or collaborating inside dashboards. Traditional request–response architecture simply can’t deliver that level of immediacy.

That’s where ASP.NET Core SignalR shines — enabling real-time two-way communication without developers having to manually manage WebSockets or fallback protocols.

In this blog, we’ll explore what SignalR is, how to build real-time chat and dashboard apps, and how to scale, secure, and deploy them for production.

  1. Introduction to SignalR

    What is SignalR? SignalR is a real-time communication library for ASP.NET Core that powers live chat apps, dashboards, multiplayer games, IoT monitoring, notifications, and more.

    How SignalR Works:

    • WebSockets (preferred)
    • Server-Sent Events (fallback)
    • Long Polling (fallback)

    SignalR provides a high-level abstraction called a Hub, enabling clients and servers to call one another effortlessly.

  2. Building a Real-Time Chat App (SignalR Server + Client)

    Step 1 — Create ChatHub.cs

    using Microsoft.AspNetCore.SignalR;
    
    public class ChatHub : Hub
    {
        public async Task SendMessage(string user, string message)
        {
            await Clients.All.SendAsync("ReceiveMessage", user, message);
        }
    }
    

    Step 2 — Register SignalR in Program.cs

    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddSignalR();
    
    var app = builder.Build();
    app.MapHub<ChatHub>("/chatHub");
    app.Run();
    

    Step 3 — HTML/JS Client

    <script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/7.0.5/signalr.min.js"></script>
    
    <div>
      <input id="user" placeholder="Name" />
      <input id="message" placeholder="Type message..." />
      <button onclick="send()">Send</button>
    </div>
    
    <ul id="messages"></ul>
    
    <script>
    const connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
    connection.on("ReceiveMessage", (user, message) => {
        const li = document.createElement("li");
        li.textContent = `${user}: ${message}`;
        document.getElementById("messages").appendChild(li);
    });
    async function send() {
        await connection.invoke("SendMessage",
            document.getElementById("user").value,
            document.getElementById("message").value);
    }
    connection.start();
    </script>
    
  3. Live Dashboard Example (Server Push Updates)

    SignalR makes it easy to stream metrics like stock prices, IoT sensor readings, or analytics to dashboards without polling.

    MetricsHub.cs

    public class MetricsHub : Hub
    {
        public async Task BroadcastMetrics(string value)
        {
            await Clients.All.SendAsync("ReceiveMetrics", value);
        }
    }
    

    Push metrics from background service

    var timer = new Timer(async _ =>
    {
        var metrics = new Random().Next(0, 100);
        var hub = app.Services.GetService<IHubContext<MetricsHub>>();
        await hub.Clients.All.SendAsync("ReceiveMetrics", metrics);
    }, null, 0, 2000);
    
  4. Scaling SignalR (Redis + Azure)

    For load-balanced environments

    • Redis Backplane for multiple servers
    • Azure SignalR Service for massive scale

    Redis Integration

    builder.Services.AddSignalR()
        .AddStackExchangeRedis("localhost:6379");
    

    Azure SignalR Service

    builder.Services.AddSignalR()
        .AddAzureSignalR("ConnectionString");
    app.MapHub<ChatHub>("/chatHub");
    
  5. Security & Connection Management
    • Use JWT or cookie authentication
    • Validate incoming messages
    • Limit message size to prevent floods
    • Use OnConnected / OnDisconnected tracking
    • Enable rate limiting for safety
    [Authorize]
    public class ChatHub : Hub { }
    
  6. Deployment & Performance Optimization

    Best Hosting Options

    • Azure App Service
    • Kubernetes (AKS)
    • Docker on Linux VM

    Performance Tips

    • Enable compression
    • Use Azure SignalR for heavy traffic
    • Keep messages small
    • Enable Redis when load balancing

Final Thoughts

SignalR brings true real-time interaction to modern applications — from live dashboards to chat apps and IoT monitoring. With scalability options like Redis and Azure SignalR Service, it can handle even enterprise-grade workloads.

At Xaylon Labs, we help organizations build scalable real-time applications including:

  • Real-time dashboards
  • Collaborative applications
  • Live monitoring platforms
  • Secure enterprise chat systems

If you're planning to build a real-time application, SignalR should definitely be in your tech stack.