Search code examples
blazor-server-sidefailoverazure-load-balancer

How does Blazor carry objects across servers when load balancing


I have some Blazor server side code that I can reduce down to this little bit:

@foreach (var employee in Employees)
{
    <tr>
        <td class="btn-group-sm">
            <button class="btn btn-outline-danger"
               @onclick="() => HandleDelete(employee)">
               Delete
            </button>
        </td>
    </tr>
}

And that calls HandleDelete(employee) on a click passing the employee object that it has persisted in the session data (I assume) to pass when the click occurs.

However, if I have multiple servers being load balanced, what happens if the submit event is sent to a different server? That different server won't have the employee object (I believe).

Does this all depend on the https session staying connected to the original server and all subsequent communication going to that server?

And if so, in a fail-over situation, what happens. In that case it's definitely a connection to a new server getting that submit action.


Solution

  • Blazor Server does not support full load balancing. The client should always stay connected with the same Blazor circuit on the same server.

    This can be accomplished by using sticky sessions on the load balancer, by using the Azure SignalR service or by using the SkipNegotiation setting.

    When using the SkipNegotiation setting, the load balancer should broadcast all SignalR messages to all nodes.

    https://learn.microsoft.com/en-us/aspnet/core/signalr/scale