Back to Insights
EngineeringJul 28, 202612 min read

Architecting Micro-Frontends with Next.js and Module Federation

Marcus Johnson

Marcus Johnson

Lead Frontend Architect

Architecting Micro-Frontends with Next.js and Module Federation

The Monolith Dilemma

As your engineering organization scales past 50 developers, a monolithic frontend architecture becomes a massive bottleneck. Build times skyrocket, merge conflicts become daily occurrences, and deployment pipelines slow to a crawl.

The solution? Micro-Frontends.

Just as microservices revolutionized the backend, micro-frontends allow independent teams to own, build, test, and deploy specific vertical slices of a web application. However, implementing this in the React ecosystem—specifically with SSR frameworks like Next.js—has historically been incredibly painful.

Enter Webpack 5 Module Federation

Module Federation allows a JavaScript application to dynamically load code from another application at runtime. This means Team A can deploy a new version of the Header component, and Team B's application will instantly consume it without requiring a rebuild.


// next.config.js
const { NextFederationPlugin } = require('@module-federation/nextjs-mf');

module.exports = {
  webpack(config, options) {
    config.plugins.push(
      new NextFederationPlugin({
        name: 'host',
        remotes: {
          shop: 'shop@https://shop.serphex.com/_next/static/chunks/remoteEntry.js',
        },
        filename: 'static/chunks/remoteEntry.js',
      })
    );
    return config;
  },
};
      

The Serphex Approach

When we rebuilt the eCommerce platform for one of our enterprise retail clients, we utilized a host-remote architecture. The host application (shell) handled global routing and authentication, while specific domains (Product Details, Checkout, User Dashboard) were distinct Next.js applications managed by different teams.

The result? Deployment times dropped from 45 minutes to 3 minutes, and feature delivery velocity increased by 300%.

Tagged:#Engineering#Engineering#Technology