Frontend System Design4 min readPremium

Server Side Rendering vs Client Side Rendering

Server-side rendering (SSR) and client-side rendering (CSR) are two different approaches to rendering web applications, and they each have their own set of advantages and disadvantages. Below, I’ll outline the pros and cons of both Server-side rendering and Client-side rendering in the context of React. Google’s Rendering on the Web article compares these approaches in depth.

Server-side Rendering (SSR):

Pros:

  1. Initial Page Load: SSR sends a fully rendered page to the client, which means that the user can see content sooner because the server generates the HTML on the initial request.
  2. SEO-Friendly: Search engines can easily crawl and index the content because the page is delivered with all the necessary markup. This is particularly important for content-heavy applications.
  3. Performance for Low-Powered Devices: SSR can perform better on low-powered devices or slow network connections because the server sends pre-rendered HTML.
  4. Graceful Degradation: If JavaScript fails to load or is slow, the user still sees the server-rendered content, although interactive features won’t work until the JavaScript runs.

Cons:

  1. Server Load and TTFB: SSR puts a higher load on the server because it renders the page for each request, and the Time to First Byte (TTFB) increases because the server must fetch data and render before it sends anything.
  2. Complexity: Implementing SSR can be more complex, especially if you have a complex application that relies heavily on client-side interactivity.
  3. Hydration Gap: The page can look ready before it is interactive. The browser still has to download the JavaScript bundle and hydrate the HTML, so clicks during that window may do nothing. After hydration, navigation and interactions work like a client-side app.

Client-side Rendering (CSR):

Pros:

  1. Faster Interactivity: Once the initial JavaScript bundle is loaded, subsequent interactions can be very fast because the client can update the DOM without needing to go back to the server.
  2. Reduced Server Load: The server is primarily responsible for sending the initial JavaScript bundle and data. After that, the client handles rendering.
  3. Rich Client Interactions: CSR is great for applications that rely heavily on client-side interactions, as it provides a more dynamic and interactive experience.

Cons:

  1. Slower Initial Page Load: The initial load time can be slower because the client needs to fetch the JavaScript bundle and then render the page on the client-side.
  2. SEO Challenges: The initial HTML is often an empty shell, and the content is populated by JavaScript. Google can render JavaScript, but rendering may be delayed, and many other crawlers and social link-preview bots don’t run JavaScript at all.
  3. Limited Performance on Low-Powered Devices: CSR can be less performant on low-powered devices or slow network connections, as they have to do more work on the client-side.
  4. Potential for Flicker: In some cases, there can be a noticeable flicker or delay as the client-side JavaScript renders the page.

SSR vs CSR at a Glance:

Aspect SSR CSR
Time to First Byte (TTFB) Slower, server renders first Fast, static shell from a CDN
First Contentful Paint (FCP) Fast, HTML arrives with content Slow, waits for JS and data
Interactivity After hydration After JS loads and renders
SEO and link previews Strong Weaker, depends on crawler
Server cost Higher, render per request Lower, static hosting
Best for Marketing, e-commerce, content Dashboards, apps behind login

How Hydration Works:

With CSR, the server sends an almost empty HTML file, and React builds the whole DOM in the browser. With SSR, the server sends the finished HTML, and React hydrates it: it renders the same tree in memory and attaches event handlers to the existing DOM instead of recreating it.


import { createRoot, hydrateRoot } from 'react-dom/client';

// CSR: the server sent an empty <div id="root"></div>, so React builds the DOM
createRoot(document.getElementById('root')).render(<App />);

// SSR: the server already sent the HTML (renderToString or renderToPipeableStream),
// so React reuses that DOM and attaches event handlers
hydrateRoot(document.getElementById('root'), <App />);

If the server and client render different markup, for example by using Date.now() or window during render, React reports a hydration mismatch. Keep the first client render identical to the server render, and move browser-only logic into useEffect.

Beyond SSR and CSR:

Modern frameworks like Next.js let you pick a rendering strategy per page, so the real interview question is usually which strategy fits each part of the app.

Strategy When HTML Is Generated Best For
Static Site Generation (SSG) At build time Docs, blogs, landing pages
Incremental Static Regeneration (ISR) At build time, then regenerated in the background after a set interval Product pages, content that changes hourly
Streaming SSR Per request, sent in chunks as data resolves Pages with slow data sources
React Server Components On the server, with no JS shipped for server components Reducing bundle size on data-heavy pages

Streaming SSR uses renderToPipeableStream with <Suspense> boundaries. The server sends the page shell immediately and streams each section when its data is ready, which improves TTFB and lets React hydrate sections independently.

How to Answer in an Interview:

Interviewers rarely want a pick between SSR and CSR. They want to see you choose per page, based on SEO needs, how personalized the data is, and how interactive the page is.

“The product listing and detail pages need SEO and a fast first paint, so I’d use SSG with ISR to keep them fresh. The cart and checkout are personalized and highly interactive, so I’d render them on the client. That keeps server cost low while giving crawlers full HTML.”

Junior Answers Senior Answers
“SSR is better for SEO.” Chooses a strategy per page and explains why
Ignores hydration Discusses the hydration gap and mismatches
Treats SSR as free Weighs TTFB, server cost, and caching
Knows only SSR and CSR Mentions SSG, ISR, streaming, or Server Components

Summary:

Choosing between SSR and CSR depends on the specific requirements of your application. If you have a content-heavy site that requires good SEO, SSR might be the better choice. However, for highly interactive applications where speed of interaction is crucial, CSR may be more suitable. In many cases, a hybrid approach (like Next.js with its ability to do both SSR and CSR) can provide the best of both worlds.