My account

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.

Not reviewedWritten with AI helpReading time: 16 minOnline shop exampleModule FederationReact and TypeScript

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.

  1. Releases wait for each other. Checkout has an urgent fix, but the release is blocked by a broken test in the account pages.
  2. Merge conflicts every day in shared files like the router and the store.
  3. 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.

  1. Each part is a business area, like checkout, not a technical layer like “all buttons”.
  2. Each part deploys on its own. That is the main benefit. If two parts must always be released together, they are not really separate.
  3. 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.

  1. One or two teams: do not split. Use one app with clear folders, code owners and import rules.
  2. A slow build: fix the build first (cache, build only what changed in a monorepo).
  3. Merge conflicts: first move shared things into clear modules with owners.
  4. “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

Split by pageParts on one pageshell: header + router/productsteam A/checkoutteam B/accountteam Csimple: one team owns one pagestart hereheader (shell team)product listteam Acartteam Bremoteharder: shared libraries,versions and fallbacks
Splitting by page is simple and should be the first step. Loading several parts into one page at run time gives more freedom, but is much harder.

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.

  1. Moving between two teams’ pages is a normal page load. Keep it fast with small bundles and HTTP caching.
  2. The same domain means the sign-in cookie works everywhere.
  3. 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:

  1. Module Federation (webpack, Rspack, and Vite with a plugin): the shell loads JavaScript modules from another team’s server at run time.
  2. Web components: each team ships a custom element, like a cart-widget tag. It works with any framework.
  3. iframes: strong isolation, but hard to size, style and make accessible. Good for third-party parts, like a payment form.
  4. 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

Not sharedshellreact 19.1 (copy 1)checkout remotereact 19.0 (copy 2)two copies: bigger download, context and hooks do not crossSharedshellcheckout remoteone react ^19 (singleton), loaded once
If each part bundles its own React, the user downloads it twice and hooks and context break between the copies. Share it as one singleton.

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' },
      },
    }),
  ],
};
  1. singleton: true means only one copy is loaded. React must be a singleton, because hooks and context only work inside one copy.
  2. 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.
  3. Share few things. Every shared library is a contract that teams must agree on. Share the framework and the design system, not every helper.
  4. 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:

  1. The URL is the best shared state: /products?category=shoes works for everyone.
  2. Props or attributes when the shell renders a part.
  3. 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);
});
  1. Write the event names and their detail types in one shared, versioned file, like an API.
  2. 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>
  );
}
  1. If the remote fails to load, the user still gets a simple link to the cart page.
  2. A new release must not break old callers. Change contracts in steps: add the new field, move callers, then remove the old one.
  3. Monitor each part with its own name in error and speed reports, so you know which team must act.

Speed and testing

  1. Set a size budget per part and check it in CI. Duplicated libraries are the most common cause of slow micro frontends.
  2. Avoid load waterfalls: the shell loads remoteEntry.js, which loads the part, which loads its data. Preload what the page always needs.
  3. Each team tests its own part fully, with fakes for the others.
  4. Contract tests check the shared events and props.
  5. 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

  1. A micro frontend is a part of the UI one team owns and deploys on its own.
  2. It solves a team problem. With one or two teams, use one well-organized app.
  3. Split by business area, and start by splitting by page.
  4. Run-time composition (Module Federation, web components) gives freedom but costs a lot.
  5. Share React as a singleton and share a versioned design system.
  6. Talk through the URL, props and versioned events, not a global store.
  7. Give every remote a fallback, a size budget and its own monitoring.

Done reading this lesson?Mark it as finished so it shows in your lessons list and report card.