Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Blazor Server provides an inspiring and powerful application development and state management model. However at present a continuous SignalR connection must be maintained between every client and the server which limits scalability. Memory also is a limiting factor.
While the stateful nature of Blazor Server is generally highly desirable, an application may have hot paths not necessarily needing statefulness. For example a news website may have very high traffic on its "/home" and "/read/{articleId}" pages but have orders of magnitude less traffic on its account management pages and discussion forum. Since article reading pages do not have high interactivity and stateful requirements, keeping these components in memory is wasteful.
Such optimizations can make the difference between a single server being able to accommodate 100,000 users or 10,000. Having this option will make Blazor Server as competitive as other technologies for consumer applications.
Describe the solution you'd like
After #30344 is implemented (which is a hard prerequisite), Blazor Server will be in a position to allow users to create stateless components. Here what I have in mind:
- If a component is marked as stateless, its state is automatically persisted after rendering and moved out of memory
- Optionally (or alternatively - if keeping some components in memory and some not is not feasible), instead of marking individual components, the user can put specific routable components in a stateless area (this is similar to the idea of MVC areas). In practice a stateless area may simply be a route-defined namespace: for example Blazor Server would allow the user to define in the App component (or somewhere else more appropriate) that all routes matching the pattern "static/**" are part of a stateless area (eg. static/read/{articleId}).
- If a component is accessed using a route belonging to a stateless area:
- All the components of the page are considered stateless
- The SignalR connection is terminated after rendering
- To support these situations, the client side javascript runtime contains a code to reestablish the SignalR connection when the user interacts with the page (and the connection is immediately terminated after rendering). If feasible, users may be allowed to define on a per-component basis which event will trigger a reconnection (default is onclick, but sometimes onmouseover etc... may also be desirable)
With stateless areas, the developer chooses to trade responsiveness for better scalability and resource management. This will typically be used on the hot path of public consumer applications as for such applications it is very common to have high-traffic public pages being fairly static (and driving conversion to turn visitors into paying customers having access to the full or actual product).
The benefit of defining stateless areas using routes is that since Blazor Components may be accessed from multiple routes, developers are empowered to - for example - provide a stateful and more interactive experience to paying customers and a static and less responsive version to non-registered users (being orders magnitude more numerous but generating less revenue) and they can do so without needing to modify their components.
This feature will allow developers to have the best of both world and will further position Blazor Server and Azure as the perfect high-productivity environment to develop the next-generation of web applications. I have a sense that this feature would be quite in reach once #30344 lands.
Additional context
No response