SSR, SSG, ISR & CSR Rendering Architectures
Next.js rendering strategies define where and when HTML and data are generated: CSR (Browser on demand), SSR (Server on every request), SSG (Build time at edge), and ISR (Static with background regeneration).
Why it matters in interviews
Visual & Interactive Explanation
Next.js Rendering Strategies Comparison Matrix
SSG
Static Site Generation
- •Instant TTFB globally
- •Cheapest hosting cost
- •Requires full rebuild to update content
ISR
Incremental Static Regeneration
- •Speed of SSG without full site rebuilds
- •On-demand revalidateTag() support
- •First visitor after expiry sees stale HTML
SSR
Server-Side Rendering
- •Always 100% fresh data
- •Access to request headers & cookies
- •Higher TTFB
- •Higher server CPU costs
CSR
Client-Side Rendering
- •Zero server rendering load
- •Rich local interactive states
- •Blank white screen during initial load
- •Poor SEO
Code Examples & Implementation
// 1. In a page or data fetcher (app/products/[id]/page.tsx)
async function getProduct(id: string) {
const res = await fetch(`https://api.example.com/products/${id}`, {
next: {
tags: [`product-${id}`], // Tagged for on-demand revalidation
revalidate: 3600, // Fallback time-based ISR: 1 hour
},
});
return res.json();
}
// 2. In a webhook route handler triggered by CMS / DB updates (app/api/revalidate/route.ts)
import { revalidateTag } from 'next/cache';
import { NextRequest, NextResponse } from 'next/server';
export async function POST(req: NextRequest) {
const { productId, secret } = await req.json();
if (secret !== process.env.REVALIDATION_SECRET) {
return NextResponse.json({ message: 'Invalid token' }, { status: 401 });
}
// Purge edge cache specifically for this product immediately!
revalidateTag(`product-${productId}`);
return NextResponse.json({ revalidated: true, now: Date.now() });
}Interview-Ready Answers
CSR renders in browser via JS bundle. SSG renders HTML at build time (fastest, static). SSR renders HTML on every HTTP request (dynamic, personalized). ISR serves static HTML from CDN and revalidates in the background after a timeout.
Official Documentation & Specifications
Follow-up Questions & Deep Dives
Common Mistakes & Anti-Patterns
- Using SSR for static pages, incurring unnecessary server CPU costs and higher TTFB
- Relying on client-side useEffect fetching for public landing pages, damaging SEO and Core Web Vitals
- Missing cache tags when using ISR, forcing developers to wait for arbitrary timeouts
Real-World Architectural Scenario
You are designing the Walmart product detail page (PDP) handling 100M daily page views. Prices change every few hours. How do you structure the rendering strategy?
Rate Your Readiness
Rate how comfortably you can explain this in an interview to update your global readiness gauge: