📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What are the render modes in a Blazor Web App in .NET 10? Explain static server-side rendering, Interactive Server, Interactive WebAssembly and Interactive Auto, where the code actually runs in each, and how you would choose between them.

Covers the four Blazor Web App render modes (static SSR, Interactive Server, Interactive WebAssembly, Interactive Auto), where code runs, prerendering, how modes are applied, and the trade-offs that drive the choice.

Junior Theory Intermediate aspnet-core blazor frontend render-modes signalr webassembly

🎯 Key points

  • Static SSR is the default: HTML rendered on the server per request, no interactivity
  • Interactive Server keeps component state on the server in a circuit over a SignalR WebSocket
  • Interactive WebAssembly downloads the .NET runtime and runs components in the browser; must call APIs, no direct DB access
  • Interactive Auto starts on Server, switches to WebAssembly once the bundle is downloaded and cached
  • Prerendering is on by default for interactive modes, so lifecycle methods run twice unless state is persisted
  • Apply with @rendermode per component/instance or globally on Routes and HeadOutlet; register AddInteractiveServerComponents/AddInteractiveWebAssemblyComponents
  • Trade-off: Server = fast start but latency and memory per user; WASM = offline-capable and scales cheaply but large first download

⏱ 30-second answer

A Blazor Web App decides per component where rendering happens. Static SSR (the default) renders HTML on the server for each request with no live interactivity, like Razor Pages. Interactive Server keeps component state on the server in a circuit and sends UI diffs over a SignalR WebSocket. Interactive WebAssembly downloads the .NET runtime and your assemblies and runs components in the browser, calling your API over HTTP. Interactive Auto starts on Server for a fast first load, then uses WebAssembly on later visits once the bundle is cached.

Interactive modes prerender on the server by default. The trade-off: Server is quick to start and keeps code private, but costs latency on every click and memory per connected user; WebAssembly scales cheaply but has a multi-megabyte first download.

🗣 Full answer (senior)

How I would answer this in an interview

"Since .NET 8, Blazor is one app model with render modes, and .NET 10 keeps that model. In a Blazor Web App, a component that has no render mode, and is not inside an interactive parent, is rendered with static server-side rendering: the server runs it once per request, sends HTML and forgets it. The project template can instead make the whole app interactive by putting a mode on Routes, so the effective default depends on how the app was created. Static SSR is great for content pages and forms that post back, and with streaming rendering and enhanced navigation it still feels fast. When a component needs real interactivity, I give it an interactive render mode.

Interactive Server runs the component on the server inside a circuit, one per browser tab, connected by a SignalR WebSocket. A click goes to the server, the component re-renders, and Blazor sends a small DOM diff back. It starts instantly and the code never leaves the server, but every interaction pays a network round trip and every connected user holds server memory. Interactive WebAssembly downloads the .NET runtime and the app's assemblies to the browser and runs the component there; it is fully client-side, so it must call an API for data, and the first visit downloads a few megabytes. Interactive Auto uses Server first and switches to WebAssembly on later visits once the files are cached. Interactive modes are prerendered by default: the server sends real HTML first, which gives search engines content to index and gives users something to see while the circuit or runtime starts, and then the component becomes interactive.

The mistake I see is turning on Interactive Server globally for everything 'because it is easiest', then discovering at go-live that 2,000 concurrent users need sticky sessions and gigabytes of RAM. I default to static SSR and add interactivity only where a page needs it."


The four modes side by side

Mode Where code runs Transport First load Per-interaction cost SEO Typical use
Static SSR Server, per request Plain HTTP Fastest Full request (enhanced nav patches the DOM) Best: full HTML Content, dashboards that refresh, simple forms
Interactive Server Server, in a circuit SignalR (WebSocket) Fast Network round trip Good if prerendered Internal LOB apps, low-latency networks
Interactive WebAssembly Browser (.NET on WASM) HTTP calls to your API Slow first visit, cached after Local, no round trip Good only if prerendered Rich client UIs, offline-ish, many users
Interactive Auto Server first, then browser SignalR, then HTTP Fast Round trip at first, local later Good if prerendered Public apps wanting both

How you apply a mode

  • On the component definition: @rendermode InteractiveServer.
  • On an instance: <Counter @rendermode="InteractiveWebAssembly" />.
  • Globally: put the mode on <Routes> and <HeadOutlet> in App.razor, which makes the whole app interactive (and turns on client-side routing). The dotnet new blazor --interactivity ... --all-interactive option generates this.
  • Child components inherit the parent's mode. You cannot nest a different interactive mode inside an interactive parent, and parameters passed from a static parent into an interactive child must be serialisable (so no RenderFragment child content across that boundary).
  • WebAssembly and Auto components must live in the .Client project, because that assembly is what ships to the browser.

Prerendering

Prerendering runs the component once on the server to produce HTML, then again when it becomes interactive. It improves perceived load time and SEO, but without care OnInitializedAsync runs twice and data loads twice, with a visible flicker. In .NET 10 the fix is the declarative [PersistentState] attribute; you can also turn prerendering off with new InteractiveServerRenderMode(prerender: false), at the cost of a blank area until the component is interactive.

Effect on users, servers and errors

Concern Static SSR Interactive Server WebAssembly
Server load CPU per request only CPU + memory per connected tab Static files + API calls
Low-end phones Best Good (thin client) Slowest start
Unhandled exception Error page for that request Circuit is terminated; user sees the error UI and must reload Error UI in the browser; logged only if you send it to telemetry
Logs Server logs Server logs Browser; ship to Application Insights

In interactive modes I wrap risky areas in <ErrorBoundary> so one failing widget does not kill the whole circuit.

When to choose which

Situation My choice
Marketing or content pages, SEO matters Static SSR, streaming rendering
Internal app, staff on the corporate network or Azure Australia East close by Interactive Server for the interactive parts
Public app, thousands of concurrent users, mobile networks WebAssembly or Auto for interactive parts
Code or rules must not reach the browser Static SSR or Server
Needs to keep working with flaky connectivity WebAssembly

Production example

On an internal claims app for [team size] users, we started with global Interactive Server. Moving the read-only list and detail pages to static SSR and keeping Interactive Server only for the claim editor cut active circuits by about [70%] and peak memory from [~3 GB to ~1 GB] per instance, with no change users noticed.

🔍 What the interviewer is checking

Checks that the candidate knows where Blazor code actually runs in each mode and can choose a mode from scale, latency and security, not habit.

Green flags

  • Explains circuits and SignalR for Server, and the runtime download for WebAssembly
  • Mentions prerendering and the double initialisation
  • Defaults to static SSR and adds interactivity per component
  • Knows WebAssembly code is public and needs an API

Red flags

  • Thinks Blazor Server and Blazor WebAssembly are still two separate project types with no Web App model
  • Cannot say where state lives in Interactive Server
  • Puts a DbContext in a WebAssembly component

📚 Learn in depth

1. One app, many renderers

A Razor component is just a class that builds a render tree. What changes between modes is who runs that class and how the output reaches the DOM.

Static SSR:
  Browser --GET /orders--> Server: run component -> HTML -> response, component discarded

Interactive Server:
  Browser <==== SignalR WebSocket (circuit) ====> Server: component lives here
     click event  ---->   handler runs, re-render, diff
     DOM patch    <----   render batch (binary)

Interactive WebAssembly:
  Browser: dotnet.wasm runtime + your .Client assemblies
     click -> handler runs locally -> DOM patched locally
     data  -> HttpClient -> your ASP.NET Core API

2. The circuit

For Interactive Server, each browser tab gets a circuit: the component instances, their state and a DI scope. Scoped services live as long as the circuit, not the HTTP request. If the WebSocket drops, the server keeps the circuit for a retention period (three minutes by default) so the client can reconnect. In .NET 10, Blazor can also persist circuit state so a user can resume after the circuit was evicted. Memory is the cost: every connected tab holds its component tree on the server.

3. WebAssembly

The browser downloads dotnet.wasm (the runtime), the framework assemblies and your .Client assemblies, trimmed and compressed. Typical apps are a few megabytes compressed on first visit and then cached and fingerprinted. Code runs on the browser's main thread. Anything in the .Client project is public: never put secrets or privileged logic there, and treat every API call from it as untrusted.

4. Auto

Auto picks Server when the WebAssembly files are not cached yet and starts downloading them in the background. On a later visit, when they are cached, the component starts as WebAssembly. Your component therefore must work in both: it cannot inject a DbContext directly, because that will fail in the browser. The usual pattern is an interface such as IOrderService with a server implementation that uses EF Core and a client implementation that calls the API.

5. Wiring in Program.cs

You register the modes you use (AddInteractiveServerComponents, AddInteractiveWebAssemblyComponents) and map them (AddInteractiveServerRenderMode, AddInteractiveWebAssemblyRenderMode). A mode you did not register throws at runtime when a component asks for it.

6. Costs to remember

  • Server: round-trip latency per event (users notice above about 100–150 ms), memory per circuit, sticky sessions or Azure SignalR Service to scale out.
  • WebAssembly: download size, slower start on low-end phones, no direct access to server resources.
  • Static SSR: no event handlers; interactivity needs a form post, enhanced navigation or a small interactive island.

Try it yourself

  1. dotnet new blazor -int Auto -o RenderModes and open the Counter page with dev tools open: watch the WebSocket on the first visit, then the .wasm downloads, then reload and see it run locally.
  2. Add Console.WriteLine in OnInitializedAsync of a prerendered page and see it run twice. Then add [PersistentState] and see the second load skipped.
  3. Throttle the network to Slow 4G in dev tools and click the counter in Server mode vs WebAssembly mode. Note the difference.
  4. Put @rendermode InteractiveServer on a component inside a WebAssembly parent and read the error.
  5. Check the published wwwroot/_framework size with du -sh after dotnet publish -c Release.

💻 Code

Register the modes in Program.cs, then apply them per component or globally.

// Program.cs (server project)
using RenderModes.Components;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents()        // circuits over SignalR
    .AddInteractiveWebAssemblyComponents();  // .Client assembly runs in the browser

var app = builder.Build();

app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();

app.MapRazorComponents

⚠ Common mistakes

  • Mistake: Making the whole app Interactive Server by default. Why it is wrong: every tab holds a circuit and server memory, and every click becomes a round trip. Instead: default to static SSR and add interactive islands where the page needs them.
  • Mistake: Injecting DbContext into a component that uses WebAssembly or Auto. Why it is wrong: the component runs in the browser, where there is no database connection. Instead: depend on an interface with a server implementation and an HTTP client implementation.
  • Mistake: Forgetting that prerendering runs OnInitializedAsync twice. Why it is wrong: data loads twice and the UI flickers. Instead: use [PersistentState] in .NET 10 or disable prerendering for that component.
  • Mistake: Turning prerendering off everywhere to avoid the double load. Why it is wrong: users and search engines get an empty shell until the circuit or runtime starts. Instead: keep prerendering and persist the state.
  • Mistake: Putting secrets or business rules in the .Client project. Why it is wrong: those assemblies are downloaded and can be decompiled. Instead: keep them on the server behind an authorised API.
  • Mistake: Writing @onclick on a component rendered with static SSR and expecting it to fire. Why it is wrong: the markup compiles and renders, but static SSR sends HTML only and no circuit or runtime is attached to handle the event. Instead: use a form post, or give that component (or a small child) an interactive render mode.
  • Mistake: Scaling Interactive Server out without sticky sessions. Why it is wrong: the circuit lives on one server, so requests landing elsewhere fail to reconnect. Instead: use session affinity or Azure SignalR Service.

🏛 Senior insight: trade-offs

The render mode is an architecture decision per page, not a project setting. I decide it from three numbers: concurrent users (memory per circuit), user latency to the server (Australia to a US region adds 150+ ms per click), and acceptable first-load size. For an internal app in Azure Australia East with a few hundred staff, Interactive Server is productive and cheap. For a public app with thousands of mobile users, WebAssembly or Auto for the interactive parts and static SSR for the rest.

Option When it fits Cost When not to
Static SSR Content, SEO, read-mostly pages No interactivity without forms/JS Rich editors, drag and drop
Interactive Server Internal apps, low latency, private logic RAM per circuit, sticky sessions, round trips Many thousands of users far from the region
Interactive WebAssembly Rich client UI, scale, offline-ish Download size, needs an API, code is public Low-end devices, secret logic
Interactive Auto Public apps wanting fast first load and client-side scale Two hosting models to test, interface per data source Small internal apps (unneeded complexity)

I measure it: Lighthouse for first load, circuit counts and memory per instance for Server, and real user latency from Application Insights.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions that Interactive Server uses SignalR and holds a circuit per user Why: Checks whether they know what scaling a circuit-based app across instances requires
    How to answer

    A SignalR server only knows its own connections and groups, held in memory. Scale out to several instances and Clients.Group("x") on server A never reaches users connected to server B. Self-hosted, you also need sticky sessions, because the negotiate request and the SSE or long-polling requests must reach the same server (WebSockets-only with SkipNegotiation avoids that). Affinity costs you even load distribution, and clients on a failed instance must reconnect. The Redis backplane fixes delivery by publishing every message to every server. It works well at moderate scale, but every server processes every message, and pub/sub doesn't buffer during a Redis failover, so run Redis highly available. Azure SignalR Service moves the client connections off your app: your servers keep a handful of connections to the service, which handles fan-out, at about 1,000 concurrent connections per Standard unit.

    For 100,000 connections, I would use Azure SignalR Service, plan units from peak connections and fan-out, and design for reconnect storms.

  2. When: Candidate argues for Blazor over a JavaScript framework Why: Checks whether they can make and document a framework decision, not just pick Blazor because the team knows C#
    How to answer

    I would treat it as an architecture decision record, not a preference vote. First list the constraints: users and devices, connectivity, accessibility, how long the app lives and who will maintain it. Then score the options on weighted criteria: team skills and hiring, ecosystem and components, render and hosting model, security fit, performance on real devices and long-term maintenance.

    Rough guidance: Blazor fits a .NET-only team building internal apps, sharing C# models and validation, if you choose the render mode carefully. React fits when the UI is complex or customer-facing and you can hire frontend specialists. Angular fits large teams that value one opinionated structure.

    Reduce the risk with a time-boxed spike on the hardest screen and record the outcome in an ADR with triggers for revisiting it. The trade-off is usually team productivity now against ecosystem and hiring breadth later.

  3. When: Candidate says Server mode sends DOM diffs over a WebSocket Why: Checks understanding of SignalR transports, fallback and authentication underneath Blazor Server
    How to answer

    SignalR is ASP.NET Core's real-time framework. A hub is a class whose public methods clients call, and the server calls methods on clients through Clients.All, Clients.Group(...) or Clients.User(...). Hubs are transient, created per invocation, so they hold no state. On connect the client calls negotiate and uses the best transport available: WebSockets, then Server-Sent Events, then long polling. Groups fan messages out to subsets of connections, but they live in memory, so a reconnecting client must re-join them (usually in OnConnectedAsync). Strongly typed hubs (Hub<IOrderClient>) replace method-name strings with an interface. Authentication uses the normal pipeline with [Authorize]. Browsers can't send an Authorization header on WebSockets or EventSource, so as a workaround the token travels as an access_token query parameter, read in JwtBearerEvents.OnMessageReceived.

    The trade-off: reconnects and routing come free, but every client holds a stateful connection that you must plan to scale.

↩ Usually asked after

More in Blazor

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me