Monolith vs Micro-frontends, and CSR vs SSR vs SSG vs ISR
Monolith vs Micro-frontends, and CSR vs SSR vs SSG vs ISR
- Two frontend system design questions: how to split the codebase (Monolith vs Micro-frontends), and where and when each page's HTML is generated (CSR, SSR, SSG, ISR).
Monolith vs Micro-frontends
Monolith
- The entire frontend lives in a single codebase with one build and one deployment.
- Its parts share code, state, and dependencies, so they are tightly coupled.
- Even a small bug fix or feature update can require testing and deploying the entire application.
- Pros:
- Simple to set up, run locally, and debug.
- Consistent UI, dependencies, and tooling.
- Easy sharing of components and state, with one optimized bundle.
- Cons:
- Builds and test suites get slower as the app grows.
- Many teams work in one codebase, so changes collide and releases need coordination.
- Upgrading a framework or library means upgrading everything at once.
- A modular monolith (clear module boundaries, often in a monorepo) keeps most of the simplicity while reducing coupling.
Micro-frontends
- The application is divided into multiple loosely coupled sub-applications, usually by business domain. For an e-commerce site: Search, Product, Cart, and Checkout.
- Each sub-application can be built, tested, and deployed independently, often by its own team, without redeploying the rest.
- A shell (container) app handles shared concerns like layout, navigation, and authentication, and loads the right micro-frontend.
- Ways to compose them:
- Route-based: each path is served by a different app, for example
/checkout routed to the checkout app through a reverse proxy.
- Runtime integration: the shell loads remote JavaScript at runtime using Module Federation or Web Components.
- Server-side composition: the server stitches fragments from different apps into one page.
- iframes: strong isolation, but poor integration and accessibility.
- Build-time integration (publishing each part as an npm package) is simpler, but you lose independent deployment.
- Tradeoffs:
- Duplicate dependencies can make bundles larger; shared libraries like React need careful version management.
- Keeping UI consistent requires a shared design system.
- Cross-app communication should be minimal: use the URL, custom events, or a small shared contract.
- More pipelines, infrastructure, and integration testing.
- When to use them: large apps with multiple independent teams that need to release separately. For a small team, a monolith is usually faster and simpler.
CSR vs SSR vs SSG vs ISR
Client-Side Rendering (CSR)
- The browser downloads a mostly empty HTML page and a JavaScript bundle. JavaScript fetches data and renders the UI on the user's device.
- Pros: rich interactivity, fast navigation after the first load, and cheap hosting because files can be served from a CDN.
- Cons: slower first meaningful paint (blank page or spinner until JavaScript loads), heavier work on low-end devices, and weaker SEO because crawlers may not run JavaScript, or index it later.
- Used for highly interactive or login-protected apps: maps, dashboards, analytics portals, and internal tools.
Server-Side Rendering (SSR)
- The server generates the page's HTML on every request, using the latest data, and sends it to the browser.
- The browser shows content immediately, then loads JavaScript to make it interactive. This step is called hydration.
- Pros: fast first content, good SEO, and always-fresh or personalized data.
- Cons: server work on every request means higher cost and a slower Time to First Byte (TTFB), and the page isn't interactive until hydration finishes.
- Used for SEO-critical, frequently changing pages: landing pages, product detail pages, and search results.
Static Site Generation (SSG)
- The page's HTML is generated once at build time and stored, usually on a CDN.
- When a request arrives, the pre-built HTML is served directly.
- Pros: the fastest and cheapest option, very reliable, and great for SEO.
- Cons: content is only as fresh as the last build, and building thousands of pages can take a long time.
- Used for content that rarely changes: documentation, blogs, and about pages.
Incremental Static Regeneration (ISR)
- Pre-built static pages are served, but they're regenerated in the background to stay up to date, without rebuilding the whole site.
- Typical behavior (for example, in Next.js with a 60-second revalidation time):
- Visitors get the cached static page instantly.
- After 60 seconds, the next request still gets the cached page, and triggers a regeneration in the background.
- Once regenerated, later visitors get the fresh page.
- Pages can also be regenerated on demand, for example when a product's price changes in the CMS.
- Pages not generated at build time can be created on their first request and then cached.
- Tradeoff: some visitors may see slightly stale content.
- Used for product pages, where most content is static but prices or stock need occasional updates.
// Next.js App Router: regenerate this page at most every 60 seconds
export const revalidate = 60;
Rendering comparison
- Modern frameworks like Next.js, Nuxt, and Astro let you choose a strategy per page or route. For example, a store can use SSG for the about page, ISR for product pages, SSR for search, and CSR for the account dashboard.
Takeaway
- Monolith: one codebase deployed together. Micro-frontends: independently deployable sub-applications owned by separate teams.
- CSR: render in the browser. SSR: render on the server per request. SSG: render at build time. ISR: static pages regenerated in the background.
References