Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

Subscribe to the newsletter

Get new articles and course lessons delivered to your inbox. No spam, unsubscribe anytime.

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 42 of the Advanced React: Performance, Architecture & Patterns course
ReactJune 28, 20264 min read

Micro-Frontends with React: Mastering Module Federation Architecture

Learn to architect scalable micro-frontends with React and Module Federation. Discover how to manage shared dependencies and handle cross-app communication.

ReactArchitectureMicro-frontendsModule FederationScalabilityWebpackjavascriptfrontend

Previously in this course, we explored mastering modular directory structures and refactoring for scalability to organize monolithic codebases. While those techniques keep a single repo clean, they don't solve the "deployment bottleneck" where a single team's error can block the entire organization. Today, we shift toward Micro-frontends, an architecture that allows teams to develop, deploy, and scale application slices independently.

The Architectural Shift: Why Micro-frontends?

Micro-frontends extend the concept of microservices to the browser. Instead of one massive bundle, you partition the UI into separate, independently deployable applications that compose at runtime.

The most robust way to achieve this today is via Module Federation, a feature introduced in Webpack 5. Unlike older iframe-based approaches—which suffer from poor accessibility and limited state sharing—Module Federation allows applications to dynamically load code from other builds at runtime as if it were a local dependency.

Core Concepts of Module Federation

  • Host: The container app that loads remote modules.
  • Remote: The micro-frontend exposing modules (components, utilities, or logic).
  • Shared Dependencies: Configuration to prevent shipping multiple copies of React (or other libraries) to the user's browser.

Worked Example: Implementing a Remote Component

Let's assume our running project requires a "Header" micro-frontend that can be updated independently of the main "Dashboard" application.

1. Configuring the Remote (Header App)

In the Header app's webpack.config.js, we expose the component:

JAVASCRIPT
const { ModuleFederationPlugin } = require(CE9178">'webpack').container;

module.exports = {
  plugins: [
    new ModuleFederationPlugin({
      name: CE9178">'headerApp',
      filename: CE9178">'remoteEntry.js', // The manifest file
      exposes: {
        CE9178">'./Header': CE9178">'./src/components/Header',
      },
      shared: { react: { singleton: true }, CE9178">'react-dom': { singleton: true } },
    }),
  ],
};

2. Consuming in the Host (Dashboard App)

In the Dashboard app, we map the remote:

JAVASCRIPT
// webpack.config.js
new ModuleFederationPlugin({
  name: CE9178">'dashboardApp',
  remotes: {
    headerApp: CE9178">'headerApp@http://localhost:3001/remoteEntry.js',
  },
  shared: { react: { singleton: true }, CE9178">'react-dom': { singleton: true } },
});

3. Dynamic Loading

We use React.lazy to import the remote component, wrapped in Suspense because the remote is fetched over the network:

JSX
import React, { Suspense } from CE9178">'react';

const RemoteHeader = React.lazy(() => import(CE9178">'headerApp/Header'));

function App() {
  return (
    <div>
      <Suspense fallback={<div>Loading Header...</div>}>
        <RemoteHeader />
      </Suspense>
      <main>Dashboard Content</main>
    </div>
  );
}

Managing Shared Dependencies and Communication

A common pitfall is version mismatch. By setting singleton: true in your shared configuration, you force Webpack to use the highest version of a library found in the dependency tree across all federated apps, preventing the "multiple React instances" bug which breaks hooks.

For cross-app communication, avoid tight coupling via shared state stores like Redux. Instead, use:

  1. Custom Events: The browser's native window.dispatchEvent for loose coupling.
  2. Props/Callbacks: Passing functions from the host to the remote via component props.
  3. URL Parameters/Query Strings: For persistent state that should survive reloads.

Comparison: Integration Strategies

StrategyCouplingDeploymentPerformance
MonolithTightAtomicBest (no network hops)
iFramesLooseIndependentPoor (heavy footprint)
Module FederationLooseIndependentExcellent (lazy loading)

Hands-on Exercise

  1. Setup: Create two separate React projects using Vite or Webpack.
  2. Expose: In Project A, expose a UserWidget component.
  3. Consume: In Project B, dynamically import UserWidget.
  4. Verify: Open the Network tab in Chrome DevTools. You should see remoteEntry.js being fetched when the page loads, followed by the specific chunk for the widget.
  5. Challenge: Pass a userName prop from the Host to the Remote and verify it renders correctly.

Common Pitfalls

  • Version Mismatch: If you don't share React as a singleton, you will encounter the dreaded "Hooks can only be called inside the body of a function component" error because the remote will try to use its own version of React.
  • CSS Leaks: Styles in micro-frontends can bleed. Use CSS Modules or Styled Components with unique namespaces to ensure your Header's styles don't conflict with the Dashboard's.
  • Over-federating: Don't turn every component into a micro-frontend. This adds significant network complexity. Only decouple boundaries that represent distinct business domains or team responsibilities.

Recap

Micro-frontends using Module Federation provide the architectural scalability required for enterprise applications. By focusing on independent deployments, shared dependency management, and loose event-based communication, you can maintain a high-velocity development cycle without sacrificing stability.

Up next: We will secure our distributed architecture in Security Best Practices in React, covering how to protect sensitive data flow across micro-frontend boundaries.

Previous lessonManaging Large-Scale Data FetchingNext lesson Security Best Practices in React
Back to Blog

Similar Posts

ReactJune 28, 20263 min read

Mastering React Patterns for Scalability: Architecture & Team Standards

Learn to unify React design patterns into a scalable architecture. Standardize component APIs and enforce team constraints to keep your codebase maintainable.

Read more
ReactJune 27, 20263 min read

Mastering Modular Directory Structures in React for Scalability

Stop drowning in a sea of components. Learn to implement feature-based directory structures, use barrel files, and manage dependencies for scalable React apps.

Part of the course

Advanced React: Performance, Architecture & Patterns

advanced · Lesson 42 of 47

  1. 1

    Deep Dive into the Reconciliation Algorithm

    4 min
  2. 2

    Profiling with React DevTools

    3 min
  3. 3

    Establishing Performance Budgets

    3 min
Read more
ReactJune 28, 20263 min read

Advanced Ref Usage: Imperative Control and DOM Integration

Master advanced Ref usage in React. Learn to manage focus, integrate non-React libraries, and handle imperative DOM tasks when declarative patterns fall short.

Read more
  • 4

    Strategic use of React.memo

    3 min
  • 5

    Mastering useCallback and useMemo

    4 min
  • 6

    State Colocation Strategies

    4 min
  • 7

    Optimizing Context Providers

    4 min
  • 8

    Advanced Context Composition

    4 min
  • 9

    Eliminating Prop Drilling

    4 min
  • 10

    Introduction to Concurrent React

    4 min
  • 11

    Non-blocking UI with useTransition

    4 min
  • 12

    Handling Deferred Data with useDeferredValue

    3 min
  • 13

    Mastering Suspense for Data Fetching

    4 min
  • 14

    Streaming Server-Side Rendering

    3 min
  • 15

    Designing Compound Components

    3 min
  • 16

    The Render Props Pattern

    4 min
  • 17

    Implementing Control Props

    4 min
  • 18

    Headless UI Architectures

    3 min
  • 19

    Modular Directory Structures

    3 min
  • 20

    Refactoring Monolithic Components

    3 min
  • 21

    Optimistic UI Updates

    3 min
  • 22

    Advanced Cache Invalidation

    4 min
  • 23

    Handling Race Conditions

    4 min
  • 24

    Server-Client State Synchronization

    3 min
  • 25

    Route-level Code Splitting

    4 min
  • 26

    Offloading Tasks with Web Workers

    3 min
  • 27

    Advanced Error Boundaries

    3 min
  • 28

    Monitoring Production Performance

    4 min
  • 29

    Final Project Audit & Optimization

    4 min
  • 30

    Advanced Hook Patterns

    3 min
  • 31

    Managing Global State with Zustand/Redux

    4 min
  • 32

    Testing Performance-Critical Components

    4 min
  • 33

    Static Site Generation (SSG) Patterns

    4 min
  • 34

    Internationalization (i18n) Architecture

    3 min
  • 35

    Accessibility (a11y) in Advanced Components

    4 min
  • 36

    Managing Third-Party Integrations

    3 min
  • 37

    Advanced Form Handling

    4 min
  • 38

    Using Portals for UI Overlays

    4 min
  • 39

    Implementing Virtualized Lists

    4 min
  • 40

    Building Design System Primitives

    3 min
  • 41

    Managing Large-Scale Data Fetching

    4 min
  • 42

    Micro-Frontends with React

    4 min
  • 43

    Security Best Practices in React

    3 min
  • 44

    Advanced Ref Usage

    3 min
  • 45

    Memoization Pitfalls

    4 min
  • 46

    Mastering React Patterns for Scalability

    3 min
  • 47

    Advanced TypeScript with React

    Coming soon
  • View full course