Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Fundamentals
  1. 1.Introduction to Frontend System Design
  2. 2.Core Frontend Architecture Concepts
  3. 3.Client-Server Interaction Fundamentals
  4. 4.Basic Performance & Accessibility Considerations
  5. 5.State Management Basics & Data Flow
  6. 6.Advanced State Management & Global Stores
  7. 7.Component Libraries & Design Systems
  8. 8.Frontend Build Tools & Development Workflows
  9. 9.Advanced Performance Optimization Techniques
  10. 10.Data Fetching Strategies & Caching
  11. 11.Frontend Security Essentials
  12. 12.Micro-Frontend Architectures
  13. 13.Real-time Communication & WebSockets
  14. 14.Observability, Monitoring, & Logging
  15. 15.Offline-First & Progressive Web Apps (PWAs)
Frontend System Design Fundamentals
12

Frontend System Design · Lesson 12 of 15 · 5 min

Micro-Frontend Architectures

This isn't about a new framework; it's about managing complexity when multiple teams ship code to the same UI. Your answer needs to focus on organizational scaling and its technical trade-offs.

After this, you'll be able to explain when to use micro-frontends and, more importantly, when not to. You'll know how to discuss the trade-offs of different composition strategies without sounding like you just read a blog post.

The first question: Should you even build one?

Micro-frontends solve organizational scaling problems, not technical ones. If you don't have multiple teams blocked by a monolithic deploy pipeline, you don't have the problem this architecture solves.

Start by questioning the premise. The default should be a well-structured monolith. Argue for micro-frontends only when the organization's structure demands it—typically, multiple autonomous teams needing to ship features independently.

The costs are significant: complex build tooling, CI/CD pipelines for each service, runtime performance overhead, and the constant challenge of maintaining a consistent user experience.

The trap: Proposing micro-frontends for a small project or a single team. It signals you know the buzzword but not the cost. Always state the prerequisites first: a large application and multiple independent teams.

Choosing your composition strategy

How you stitch the pieces together determines the architecture's success. There are three main approaches. Your choice depends on the type of application and your tolerance for complexity.

1. Build-Time Composition This is publishing micro-frontends as npm packages and having a container application install them as dependencies. It's simple, but it's not a true micro-frontend architecture.

You lose the primary benefit: independent deployments. To update a micro-frontend, you must release a new version of the package and then redeploy the container application. This is a modular monolith, not a micro-frontend system.

2. Server-Side Composition A web server or CDN layer assembles a page from different, independently rendered HTML fragments. This uses technologies like Server-Side Includes (SSI) or Edge-Side Includes (ESI).

This is a great fit for content-heavy sites where most of the UI is not highly interactive. It's less suitable for complex, stateful SPAs where client-side coordination is constant.

3. Client-Side Composition This is the most common approach for modern web apps and the one you'll likely discuss in an interview. The browser downloads a container or "shell" application, which then orchestrates the loading and mounting of the individual micro-frontends.

  • Iframes: The simplest method. They provide perfect CSS and JavaScript isolation. However, they are heavy, communication requires postMessage, and creating a seamless UX across frame boundaries is difficult. Use them for embedding truly third-party or legacy content where isolation is paramount.
  • Module Federation: The current standard for building micro-frontend SPAs. It allows separately compiled applications to share code and dependencies at runtime, behaving as a single, cohesive application.

How Module Federation works

Webpack's Module Federation lets a JavaScript application dynamically load code from another application. It creates a "host" (the shell) that consumes code from "remotes" (the micro-frontends).

The key is that they can also share dependencies. If the host and two remotes all depend on React, Module Federation can ensure only one instance of React is loaded, preventing version conflicts and bloat.

Configuration is handled in webpack.config.js. You only need to understand three properties of the ModuleFederationPlugin:

  • remotes: Used by the host to list the remotes it can consume.
  • exposes: Used by a remote to declare which modules it makes available.
  • shared: Used by all applications to list dependencies that should be shared and de-duplicated, like react or lodash.

Here is the essential configuration for a host and one remote.

// In the host's webpack.config.js
// ... other webpack config
plugins: [
  new ModuleFederationPlugin({
    name: 'host',
    remotes: {
      // 'cart' is the alias used in imports
      // 'cart@...' is the location of the remote's entry file
      cart: 'cart@http://localhost:3001/remoteEntry.js',
    },
    shared: { react: { singleton: true }, 'react-dom': { singleton: true } },
  }),
],
// In the cart micro-frontend's webpack.config.js
// ... other webpack config
plugins: [
  new ModuleFederationPlugin({
    name: 'cart',
    filename: 'remoteEntry.js',
    exposes: {
      // Expose './src/CartWidget.js' to be imported as 'cart/CartWidget'
      './CartWidget': './src/CartWidget.js',
    },
    shared: { react: { singleton: true }, 'react-dom': { singleton: true } },
  }),
],

The host application can then dynamically import the exposed module using React.lazy or a simple import().

Handling communication and consistency

Isolating teams is the goal, but the final product must feel like one application. This requires clear contracts for communication and a strategy for visual consistency.

State Sharing and Communication Micro-frontends should not share state directly.

  • Global State (e.g., Auth): The shell application is responsible for authentication. It should pass the user's status and token down to each micro-frontend as props.
  • Cross-MFE Communication: When one micro-frontend needs to trigger an action in another (e.g., a "product list" MFE adds an item to a "cart" MFE), use a global event bus. A simple window.dispatchEvent(new CustomEvent(...)) is often enough. This decouples the micro-frontends; they only need to agree on event names and payloads, not on each other's internal implementation.

Styling and UI Consistency Uncoordinated styling is the fastest way to make your app feel broken.

  • CSS Isolation: Global CSS is a major risk. Use a method that scopes styles to each micro-frontend, such as CSS Modules, styled-components, or other CSS-in-JS libraries. Wrapping micro-frontends in Web Components to leverage the Shadow DOM is an even stronger isolation technique.
  • Shared Design System: This is non-negotiable. All teams must consume a shared component library (e.g., as an npm package) to ensure buttons, forms, and layout primitives are consistent. The design system is the source of truth for the UI.

The trap: Forgetting to share core libraries. If each micro-frontend loads its own copy of React, you'll have a bloated app and hooks or context will break. The shared: { react: { singleton: true } } configuration in Module Federation is critical to prevent this.

Try it

In 15 minutes, sketch the micro-frontend boundaries for a standard e-commerce product page. Identify at least four distinct micro-frontends (e.g., header, image gallery, product details, recommendations). For one of them, define its API contract: what props does it need from the shell, and what custom events does it fire?

Next: We'll move from architectural patterns to real-time data flow in Real-time Communication & WebSockets.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Frontend Security Essentials

Next

Real-time Communication & WebSockets