Debunking Blazor Server Scaling Myths: How .NET 8 Enhances Performance with New Render Methods

 


Note: this is an update from Yes, Blazor Can Scale, 4/1/2021

From the very beginning of Blazor Server's release, skeptics have claimed that it cannot scale effectively, often citing a limit of 5,000 concurrent users. This misconception stems from misunderstandings about Blazor Server's architecture and capabilities. With the advent of .NET 8, Blazor Server has introduced new render methods that significantly enhance its scalability and performance. In this post, we'll break down these myths and explore how the latest advancements in Blazor Server make it a robust solution for modern web applications.

Understanding the "Limit" for Users

When Microsoft discusses the need to scale an application, they imply that if a normal response for any concurrent user takes longer than 200 milliseconds, the system isn't performant and requires scaling. We'll adopt this definition:

If any normal user response exceeds 200 ms, the system needs to scale for concurrent users.

By "normal response," we refer to typical interactions like page loads or form submissions, excluding large database queries or intensive computations.

What Is Scaling?

Scaling ensures your application maintains optimal performance under increasing load. There are two primary ways to scale:

  • Vertical Scaling (Scale Up): Enhancing the capacity of a single machine by adding more CPU, memory, or storage.
  • Horizontal Scaling (Scale Out): Adding more machines to distribute the load across multiple servers.

Vertical Scaling with Blazor Server

In earlier versions, a Blazor Server application running on a 1-core machine with 3.5 GB of memory could support up to 5,000 concurrent users. Upgrading to a machine with 4 cores and 16 GB of memory increased this capacity to 20,000 concurrent users.

With .NET 8, performance optimizations and new render methods have pushed these boundaries even further. The introduction of streaming rendering and server-side component rendering allows for more efficient resource utilization, enabling a single server to handle more concurrent connections without compromising on response times.

New Render Methods in .NET 8 Blazor

  • Streaming Rendering: This method allows components to render progressively, sending chunks of HTML to the client as they become available. It reduces the time to first render and improves perceived performance.
  • Server-side Component Rendering: Components can now be pre-rendered on the server and hydrated on the client. This reduces the load on the server by offloading some rendering tasks to the client-side, thus handling more users efficiently.

Horizontal Scaling with Blazor Server

Scaling horizontally introduces complexity due to Blazor Server's reliance on SignalR for real-time communication between the client and server. Here's how to overcome common hurdles:

  1. SignalR Connections: Blazor Server uses SignalR hubs for client-server communication. In .NET 8, SignalR has been optimized for better scalability and performance.
  2. Stateful Connections: Each client maintains a persistent connection to the server. Ensuring clients reconnect to the same server instance is crucial.
  3. Sticky Sessions (ARR Affinity): This ensures that a user's session remains on the same server across multiple requests.

Solutions for Effective Horizontal Scaling

  • Azure SignalR Service: Offloading SignalR connections to the Azure SignalR Service allows you to scale your Blazor Server app across multiple servers without worrying about sticky sessions. The service manages client connections and distributes them efficiently.
  • Enable ARR Affinity: In your Azure App Service configuration, turn on ARR Affinity under the General Settings. This enables sticky sessions, ensuring that a user's session remains consistent across requests.

Improved Limits with .NET 8

Previously, the Azure SignalR Service had a maximum limit of 100,000 concurrent connections. With .NET 8 and updates to Azure services, this limit has been increased, allowing even more concurrent users. Check the latest Azure SignalR Service documentation for up-to-date limits.

Uber Scale: Beyond 100,000 Concurrent Users

For applications requiring "uber" scale (millions of concurrent users), additional architectural strategies are necessary. Blazor Server might not be the optimal choice in these scenarios due to the stateful nature of SignalR connections. However, Blazor WebAssembly or a combination of microservices and serverless architectures can be considered for such massive scale requirements.

Cost Considerations

Scaling comes with financial implications. Let's update our cost estimates based on the latest Azure pricing and the efficiencies introduced in .NET 8.

Example: Supporting 200,000 Concurrent Users

  1. Azure SignalR Service:

    • Estimated Cost: With improved efficiency, you might need fewer units. Suppose you need 80 units instead of 100.
    • Calculation: 80 units × 1 month × $0.0671 = $4,069.44
  2. Azure App Services:

    • Servers Needed: With .NET 8 optimizations, you might need only 4 servers instead of 5.
    • Estimated Cost: 4 servers × 1 month × $489.10 = $1,956.40

Total Estimated Monthly Cost: $6,025.84

When compared to traditional web applications using CDNs and minimal server infrastructure, the costs are higher. However, the rich interactive experience and real-time capabilities of Blazor Server can justify the investment, depending on your application's needs.

Summary

The key takeaway is that Blazor Server can scale effectively, especially with the enhancements introduced in .NET 8. The new render methods and SignalR optimizations allow for better performance and higher user capacity. Before deciding whether Blazor Server is right for your application, consider the following:

  • Understand Your User Load: Know your average and peak concurrent user numbers.
  • Evaluate Costs vs. Benefits: Weigh the enhanced user experience against the infrastructure costs.
  • Stay Updated: Keep abreast of the latest features and improvements in .NET and Azure services.

Blazor Server applications are a viable solution for many modern web applications, offering a seamless and interactive user experience. Don't let misconceptions limit your technology choices; instead, base your decisions on thorough research and an understanding of your application's unique requirements.


References:

Comments

Popular posts from this blog

Yes, Blazor Server can scale!

Blazor - Cool Blur Loading Page

Blazor new and improved Search Box