Micro frontends
Micro frontends split one big frontend into parts that different teams build, test and deploy on their own. They solve a team problem, not a code problem - with one team they only add cost. Start by splitting by page; load parts into one page at run time only when you must. Then the hard work begins - one shared React, a shared design system, simple contracts between parts, and a fallback when a part fails to load.
Author: bezzad
Contents
The problem: four teams, one release
Our online shop grew. There are now four frontend teams: products, checkout, account and the platform team. They all work in one React app with one build and one release.
- Releases wait for each other. Checkout has an urgent fix, but the release is blocked by a broken test in the account pages.
- Merge conflicts every day in shared files like the router and the store.
- The build takes 20 minutes, even for a one-line change.
Someone says: “Let’s use micro frontends.” Maybe. A specialist first asks if this is the real problem, and then picks the simplest way to split.
What micro frontends are
A micro frontend is a part of the user interface owned by one team from start to end: code, tests, build and release. The shop is the sum of these parts.
- Each part is a business area, like checkout, not a technical layer like “all buttons”.
- Each part deploys on its own. That is the main benefit. If two parts must always be released together, they are not really separate.
- It is an organization tool. It lets teams move without waiting for each other. It does not make code better by itself.
When not to use them
Micro frontends have a real cost: more repos and pipelines, shared library versions, slower pages if done badly, and harder end-to-end testing.
- One or two teams: do not split. Use one app with clear folders, code owners and import rules.
- A slow build: fix the build first (cache, build only what changed in a monorepo).
- Merge conflicts: first move shared things into clear modules with owners.
- “Every team wants its own framework”: this is a reason against, not for. Users pay for it with a bigger download.
Use micro frontends when several teams really block each other, and each team owns a clear business area.
Two ways to split
1. Split by page (route). Each team owns whole pages. A reverse proxy or CDN sends /checkout to the checkout app and /products to the products app, all on the same domain.
- Moving between two teams’ pages is a normal page load. Keep it fast with small bundles and HTTP caching.
- The same domain means the sign-in cookie works everywhere.
- A shared header comes from a shared package, or from a small shell that each app includes.
2. Parts on one page (run-time composition). One page shows parts from several teams, like the cart widget from checkout inside the product page. Common tools:
- Module Federation (webpack, Rspack, and Vite with a plugin): the shell loads JavaScript modules from another team’s server at run time.
- Web components: each team ships a custom element, like a cart-widget tag. It works with any framework.
- iframes: strong isolation, but hard to size, style and make accessible. Good for third-party parts, like a payment form.
- Server or edge composition: the server puts HTML fragments from several teams into one page before sending it.
A build-time split (each part is an npm package that the shell installs) is not a micro frontend in the full sense: one release still contains everything.
Shared libraries
With Module Federation, the shell names the remote and the libraries that must be shared:
// webpack.config.js of the shell
const { ModuleFederationPlugin } = require('webpack').container;
const CHECKOUT = 'https://cdn.shop.example/checkout/remoteEntry.js';
module.exports = {
plugins: [
new ModuleFederationPlugin({
name: 'shell',
remotes: {
checkout: `checkout@${CHECKOUT}`,
},
shared: {
react: { singleton: true, requiredVersion: '^19.0.0' },
'react-dom': { singleton: true, requiredVersion: '^19.0.0' },
},
}),
],
};
- singleton: true means only one copy is loaded. React must be a singleton, because hooks and context only work inside one copy.
- requiredVersion is a promise between teams. If checkout needs React 20 and the shell has 19, you get a warning and maybe a bug. Upgrade such libraries together.
- Share few things. Every shared library is a contract that teams must agree on. Share the framework and the design system, not every helper.
- The design system is a versioned package with tokens and components, so all parts look like one shop.
Talking between parts
Parts must not reach into each other. Keep the contract small and clear:
- The URL is the best shared state: /products?category=shoes works for everyone.
- Props or attributes when the shell renders a part.
- Browser events for “something happened”:
// checkout team: tell others that the cart changed
window.dispatchEvent(new CustomEvent('cart:changed', {
detail: { count: 3 },
}));
// shell team: update the cart badge in the header
window.addEventListener('cart:changed', (event) => {
const { count } = (event as CustomEvent<{ count: number }>).detail;
setCartBadge(count);
});
- Write the event names and their detail types in one shared, versioned file, like an API.
- Avoid one global store shared by all parts. It ties every team to every other team again.
When a part fails
A remote is another server. It can be slow, down, or deployed with a bug. The shop must still work.
import { lazy, Suspense } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
const CartWidget = lazy(() => import('checkout/CartWidget'));
export function HeaderCart() {
return (
<ErrorBoundary fallback={<a href="/checkout/cart">Cart</a>}>
<Suspense fallback={<span className="cart-skeleton" />}>
<CartWidget />
</Suspense>
</ErrorBoundary>
);
}
- If the remote fails to load, the user still gets a simple link to the cart page.
- A new release must not break old callers. Change contracts in steps: add the new field, move callers, then remove the old one.
- Monitor each part with its own name in error and speed reports, so you know which team must act.
Speed and testing
- Set a size budget per part and check it in CI. Duplicated libraries are the most common cause of slow micro frontends.
- Avoid load waterfalls: the shell loads remoteEntry.js, which loads the part, which loads its data. Preload what the page always needs.
- Each team tests its own part fully, with fakes for the others.
- Contract tests check the shared events and props.
- A few end-to-end tests on the real joined shop: open a product, add to cart, pay.
Common mistakes
| Mistake | Result | Better way |
|---|---|---|
| Micro frontends for one small team | More work, no faster releases. | One app with clear modules and owners. |
| Splitting by technical layer | Every feature needs all teams. | Split by business area. |
| Each part bundles its own React | Bigger download, hooks break. | Share React as a singleton. |
| A global store shared by all parts | Teams are tied together again. | URL, props and versioned events. |
| No fallback for a remote | One failing part breaks the whole page. | Error boundary with a simple fallback. |
| Different frameworks per team | Slow pages, nobody can help another team. | One framework, one design system. |
Summary in 7 lines
- A micro frontend is a part of the UI one team owns and deploys on its own.
- It solves a team problem. With one or two teams, use one well-organized app.
- Split by business area, and start by splitting by page.
- Run-time composition (Module Federation, web components) gives freedom but costs a lot.
- Share React as a singleton and share a versioned design system.
- Talk through the URL, props and versioned events, not a global store.
- Give every remote a fallback, a size budget and its own monitoring.