0%
Frontend System Design Interviews: Components, Rendering, State, Caching and Performance
Rendering Strategies
Every frontend design has to answer a basic question early: where is the HTML for each screen produced, and when? The answer, the rendering strategy, decides how fast the first content appears, how soon the page responds to input, how well it is indexed, how much server capacity it needs and how complex the code becomes. In the framework from the first lesson, you choose a strategy at a high level during the architecture step and justify it in detail when the interviewer probes.
This lesson walks through the main options: client side rendering, server side rendering, static generation, incremental regeneration, streaming, hydration and its variants, islands, server components and edge rendering, and finishes with how to choose per route. The metrics used to measure the result, such as the time to the largest content and interaction delay, are covered in depth in the performance lesson; here they appear only as the outcomes each strategy affects.
Client side rendering
With client side rendering, the server, usually a CDN, returns a nearly empty HTML document: a root element, links to the script bundle and perhaps some styles. The browser downloads the bundle, parses and runs it, and the application code then fetches data from the API and renders the interface into the root element.
The strengths are real. Hosting is simple and cheap, because the HTML and bundle are static files on a CDN. After the first load, navigation between screens is fast, because the application is already running and only needs data. The server API can be shared with mobile apps. The programming model is simple: everything happens in one environment.
The weaknesses are about the first visit. Nothing useful appears until three things happen in sequence: the bundle downloads, the bundle runs and the data request returns. On a slow phone with a high latency network, that can take several seconds. Search crawlers and link preview fetchers that do not run JavaScript, or run it late, see an empty page. And the whole interface depends on a large script, so the main thread is busy at exactly the moment the user first tries to interact.
When client rendering fits
Client rendering is a reasonable choice for applications behind a login where search visibility does not matter, users return often so the bundle is cached, sessions are long and interactions are rich: an email client, a project management tool, an analytics dashboard, a design editor. Even there, the first load can be improved with a small initial bundle, code splitting by route and an application shell cached by a service worker so repeat visits start instantly.
It is a poor choice for public, content heavy pages where first visit speed and indexing matter: articles, product pages, landing pages, public profiles.
Server side rendering
With server side rendering, the server runs the application code for each request, fetches the data the page needs and returns complete HTML with the content already in it. The browser paints that HTML immediately. Then the script bundle downloads and runs and attaches event handlers to the existing markup, a step called hydration, after which the page behaves like a client rendered application.
The main benefit is that meaningful content arrives in the first response. The data fetch happens on the server, usually close to the database, so it is often faster than a fetch from a distant phone. Crawlers and preview fetchers see real content and metadata. On slow devices, the user can at least read the page while the script is still loading.
The costs of server rendering
Server rendering is not free. The server must render HTML for every request, which needs compute capacity that scales with traffic, and that capacity must be operated, monitored and paid for. The time to the first byte increases, because the server waits for data before it can respond; if one data source is slow, the whole page waits, unless you use streaming, covered later. Personalised pages are harder to cache at the CDN, because each user's HTML differs.
The code also becomes more complex. Components must run in two environments, server and browser, so code that touches browser only features such as window size or local storage must be guarded. The HTML the server produces must match what the client produces during hydration, or the framework reports mismatches and may re-render. And the page still downloads the full script to hydrate, so server rendering improves when content appears but does not, by itself, reduce the time until the page responds to input.
Comparing the two on one page
It helps to compare the two strategies on the same page with rough steps. For a feed on a mid range phone over a high latency network, client rendering needs the HTML shell, then the bundle, then the data, each waiting on the previous, before any post appears. Server rendering needs one request for HTML that already contains the first posts, while the server makes its data request over a fast internal network; the bundle then loads in parallel with the user reading.
So server rendering usually wins on the time to first content for first visits, and client rendering is simpler and cheaper to run. Both pay for the script before the page is interactive. The rest of this lesson is largely about strategies that keep the benefit of server produced HTML while reducing either the server cost or the script cost.
Single page applications and navigation
Whichever strategy produces the first page, most modern applications behave as single page applications after the first load: navigation fetches data or rendered fragments and updates the page without a full reload. Server rendered frameworks typically render the first page on the server and then handle later navigations on the client. This is worth stating in the interview, because it means the rendering strategy mainly affects the first visit to each route and the behaviour on a hard reload, while later navigations depend on prefetching and the client data layer.
What the interviewer is checking
The interviewer checks that you can describe what happens in sequence for each strategy, name the cost on the client and the server, and connect the choice to requirements: public and indexed, first visit speed on slow devices, server budget and how interactive the screen is. A candidate who says server rendering is better for performance has given a slogan. A candidate who says server rendering moves the data fetch to the server and puts content in the first response, which helps the first content time for our mostly first time mobile visitors, at the cost of render capacity and a hydration step, has given a design.
Prerendering for crawlers is a workaround
Some teams keep a client rendered app and add a prerendering service that runs the app in a headless browser for crawlers and serves them the resulting HTML. This can rescue indexing for an existing product, but it means crawlers and users see different pipelines, the prerendered copies can go stale, and link preview fetchers or new crawlers may not be detected. In an interview, treat it as a migration step for a legacy app rather than a design you would choose for a new public product.
Making client rendering faster on first load
If you do choose client rendering, there are several ways to shorten the chain. Inline the critical styles and a small loading skeleton in the HTML shell, so the user sees structure at once instead of a blank page. Start the data request in parallel with the bundle, for example with a preload hint for the API call or a tiny inline script that begins the fetch before the main bundle runs, which removes one link from the chain. Keep the code needed for the first route small and load other routes on demand. And cache the shell and bundle with long lifetimes and content hashed file names, so returning users skip the downloads entirely. None of these makes client rendering equal to server rendering on a cold first visit, but together they often turn a slow start into an acceptable one for a logged in product.
A quick sizing exercise
It is worth doing rough arithmetic aloud. Suppose the round trip time on the target network is about 150 milliseconds and the bundle takes about a second to download and another second to parse and run on the reference phone. Client rendering then needs the HTML round trip, the bundle download, the execution and the data round trip before content appears, which comes to well over two seconds. Server rendering with a 200 millisecond server render puts content on screen after roughly one round trip plus the render and the HTML transfer, which is under a second. The numbers are invented, but the exercise makes the difference concrete and shows the interviewer that you reason from the sequence rather than from a preference.
When you name a rendering strategy, say what happens in order: what the first response contains, what the browser must download and run, and when data is fetched. The sequence makes the cost and the benefit obvious, and it is what the interviewer is listening for.