What is the best way to use a SignalR service for my Blazor RenderMode.InteractiveServer app?

David Thielen 2,626 Reputation points
2024-07-09T17:37:42.7533333+00:00

Hi all;

I've read in numerous places that having my Blazor server use a SignalR service will let it handle a lot more simultaneous requests. So I want to add this. I've seen three very different ways describing how to do this:

  1. Write a ton of code
  2. Create a SignalR app
  3. Connect to a SignalR service
  4. Another approach???

I like option 3 best because it seems like a very clean way to accomplish this. But that does not mean it's the optimum approach.

So which is the optimum approach?

thanks - dave

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,484 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
132 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 60,706 Reputation points
    2024-07-09T18:30:24.97+00:00

    your question is not clear. does your Blazor app use signal/r for features not related to the Blazor Server circuit (example a chat app)? that what your links 1 & 2 refers to.

    the standard configuration is each webserver hosting your Blazor app is also the Signal/r Hub. But it can be configured to use the Azure Signal/r service (your link 3).

    using Azure Signal/R for the Blazor circuit has a couple pros:

    • it's a large farm and can handle a lot of connections (large scaling)
    • its geographical, so the client may have a faster connection, less latency
    • allow more connections if web host limits the number of websockets (ex: azure service apps). this is probably the main reason to use Azure Signal/R

    it also has some cons:

    • its a separate service so may add latency, especially for on-prem servers.
    • additional cost.

    Blazor server interactive will never match the scaling/performance of client interactive, except perhaps startup performance.

    in Blazor server interactive, every event is detected by JavaScript, sent to the server. the server process the event, and build a new render tree, a datagram of the render tree changes its sent to the client. the client updates its copy of the render tree, and then updates the browser dom. If your Blazor app was event tracking each character or mouse move, it's a trip to the server and back for each event.


0 additional answers

Sort by: Most helpful