Micro-Frontends: When to Split the Monolith
The Front-End Scaling Problem
Monolithic frontends work beautifully for small to medium-sized teams. But when your organization grows to 50+ engineers working on the same Next.js or React repository, deployment pipelines clog, testing times skyrocket, and the "blast radius" of a single bad commit extends to the entire product.
Enter the Micro-Frontend (MFE)
Micro-frontends apply the concept of microservices to the UI layer. An application is composed of independent, deployable units—often maintained by distinct teams. E.g., Team A handles the "Checkout" flow, while Team B manages the "User Profile" component.
The Module Federation Approach
Webpack 5's Module Federation completely revitalized the MFE pattern. Unlike older approaches that relied on rigid iframes or custom Web Component wrappers, Module Federation allows an application to dynamically load code from another application at runtime, sharing dependencies like React or Lodash seamlessly in the browser to prevent bloated payloads.
// Example Webpack Module Federation Setup
new ModuleFederationPlugin({
name: "checkoutApp",
filename: "remoteEntry.js",
exposes: {
"./CheckoutWidget": "./src/components/CheckoutWidget",
},
shared: { react: { singleton: true }, "react-dom": { singleton: true } }
});
When is it a Terrible Idea?
Using MFEs inherently increases infrastructural complexity. If your teams are tightly coupled, or your application is highly state-interdependent, applying an MFE architecture will only lead to "integration nightmare." You should only split the monolith when organizational scaling demands it, never just for the sake of granular tech.
In modern architecture, the line between over-engineering and brilliant foresight is thin. Use MFEs strictly as a Conway's Law scaling tool, not a default starting point.