4 : Signals R gr8

07 Jan 2022

This time Andy and Rowan are discussing SignalR. We'll be discussing what you can use it for, how we've used it and how to get started.

Random fact

You won't believe where McDonald's opened its first drive-thru - Soldiers at Fort Huachuca (Sierra Vista’s) were not allowed to appear in public in their work or duty uniforms, a longstanding rule that had to do with military decorum, according to Steve Gregory, a technician at the Fort Huachuca Museum.

Instead, he pushed out a small portion of the wall, creating just enough space for an attendant. He installed a small sliding window, low enough to be reached via car window, wide enough to pass burgers and a side of fries.

On Jan. 24, 1975, the world’s largest fast-food franchise opened its first drive-through.


  • What is SignalR
    • Add real-time functionality to your dashboards, maps, games and more. What is real-time functionality? It's the ability to have your server-side code push content to connected clients as it happens, in real-time.
    • http is a stateless one way protocol - SignalR changes that in a way
    • Duplex / two way communication
  • Is it a new thing?
    • Been out since at least 2013, builds on existing web technologies
    • Other eco systems do have support for web sockets and long polling
    • SignalR provides a nice developer experience with low barrier to entry and nice abstractions in the form of Hubs, Clients etc
  • What have you used it for
    • Comparison platform - retrieving quotes from many external providers, where each provider will come back at different times.
      • SignalR great to update the UI when all quotes have returned
      • Aggregation operations like min price, number of providers quoted etc
      • Used with a Vue client - JS client npm package worked well inside Vue
    • Admin interface - client used as an event handler off the back of quote requests to provide real-time view of what quotes were being requested, to broadcast to other clients to update dashboards etc
  • Only for .net languages?
    • .NET client
    • Java client
    • JavaScript client - now an npm package
  • Where can it be used
    • Web app
    • Console app
    • Windows Service / daemon (linux)
    • Excel
    • Cross platform
  • But it needs newer tech doesn't it?
    • Browser versions supported - IE, Edge, Chrome, Safari, Mobile

    • Communication channels

      • HTML 5 transports
        • Websockets - ideal
        • Server Sent Events - server push over http

      Commet transports (long-held http requests)

      • Ajax Long polling
      • Forever Frame (IE only) - hidden iframe making request to server that does not complete, but server sends script to client which is immediately executed
  • Infrastructure requirements
    • Do you need extra servers
      • For server farm environments
        • Need to enable session affinity (sticky sessions) on ARRs, load balancers
        • Need to use a SignalR Backplane if you want to broadcast to all clients -
          • Need to replace default IMessageBus which only knows about local machine
          • Currently provides 3 backplanes:
            • Azure Service Bus
            • Redis
            • Sql server
          • simple to setup - install nuget package, configure connection etc in Startup.cs
            • Microsoft.AspNet.SignalR.ServiceBus Microsoft.AspNet.SignalR.StackExchangeRedis Microsoft.AspNet.SignalR.SqlServer
            • GlobalHost.DependencyResolver.UseServiceBus(connectionString, "YourAppName"); GlobalHost.DependencyResolver.UseStackExchangeRedis("server", port, "password", "AppName"); GlobalHost.DependencyResolver.UseSqlServer(sqlConnectionString);
    • Azure SignalR Service - simplifies ARR config and takes care of the backplane for you
  • Can it cope with thousand of users?
    • Very efficient and scales well by default
    • Might need to tune web server / ASP.NET to support an increased number of concurrent connections
      • tweaking IIS config - Max Concurrent Requests per app
      • teaking ASP.NET config - Maxium Concurrent Requests Per CPU, Request Queue Limit
    • See performance page on the SignalR wiki on Github
  • Communication protocol
    • SignalR is open-source on GitHub, just like the rest of .NET. In addition to the source code, the protocol specification for communication between hubs and clients is open too.

OS project/utility of the week

We had a few this week...

Polly (http://www.thepollyproject.org/) quality logo :-)

express resilience and transient fault handling policies like:

  • Retry, Circuit Breaker, Timeout, Bulkhead Isolation, Fallback
  • lovely fluent policy declaration api

FluentDocker (https://github.com/mariotoffia/FluentDocker)

Basically allows you to build up docker containers using a fluent syntax. For example...

ngrok (https://ngrok.com/docs) - One command for an instant, secure URL to your localhost server through any NAT or firewall.