Full answer
Micro-frontends apply the microservice idea to the interface: a checkout team, a catalog team and an account team each own a vertical slice with its own repository, pipeline and release schedule. A shell (host) application composes them.
Integration styles:
- Build-time: each slice is an npm package. Simple, but any change needs a rebuild and release of the host, so deployment is not independent.
- Run-time with Module Federation or native ES modules: the host loads remote bundles by URL when needed, and can share libraries such as React as singletons so only one copy runs. Teams deploy independently.
- iframes: strong isolation of styles, scripts and failures, at the cost of routing, sizing, accessibility and performance difficulty.
- Server-side composition: edge or origin stitches HTML fragments, often with web components or streaming.
Contract design is the important part. A framework-agnostic contract means each remote exports mount(element, props) and returns an unmount function. The host does not care how the remote renders, and can mix React versions in the extreme case. Communication goes through props, custom DOM events or a small event bus, not shared global state. Shared concerns such as authentication, routing base paths, design tokens and analytics are provided by the shell and a shared design system.
Pitfalls: loading two React copies breaks hooks and context across the boundary (share React as a singleton, or keep remotes isolated), CSS leaks (use CSS modules, scoped naming or Shadow DOM), bundle bloat from duplicated libraries, version skew between the shell and remotes, and a worse developer experience on a shared page. Error isolation matters: wrap each remote in an error boundary and a loading fallback.
When not to use them: small teams, one product with a shared release cycle. A well-structured monorepo with feature folders gives most benefits at lower cost.
The example uses two remotes with the mount contract and an error-isolated host. The remotes are in-file stand-ins for bundles that would be loaded by URL.
import { createRoot } from 'react-dom/client';
// Each remote exposes a framework-agnostic contract: mount(element, props) returns unmount().
const remotes = {
catalog: async () => ({
mount(element, props) {
const root = createRoot(element);
root.render(<h2>Catalog for {props.user}</h2>);
return () => root.unmount();
},
}),
checkout: async () => ({
mount(element) {
const root = createRoot(element);
root.render(<button onClick={() => element.dispatchEvent(new window.CustomEvent('checkout:done', { bubbles: true }))}>Pay</button>);
return () => root.unmount();
},
}),
broken: async () => {
throw new Error('remote failed to load');
},
};
async function mountRemote(name, element, props) {
try {
const remote = await remotes[name]();
return remote.mount(element, props);
} catch (error) {
element.textContent = 'This section is unavailable: ' + error.message;
return () => {};
}
}
const host = document.getElementById('root');
const slots = ['catalog', 'checkout', 'broken'].map((name) => {
const slot = document.createElement('section');
slot.dataset.remote = name;
host.appendChild(slot);
return { name, slot };
});
host.addEventListener('checkout:done', () => console.log('host received checkout:done'));
const unmounts = await Promise.all(slots.map(({ name, slot }) => mountRemote(name, slot, { user: 'Asha' })));
await new Promise((resolve) => setTimeout(resolve, 30));
console.log(host.innerHTML);
host.querySelector('button').click();
unmounts.forEach((unmount) => unmount());This ran as a script. The remotes are local stand-ins for bundles that a real host would import by URL. The third one fails on purpose to show that a broken remote does not break the host. Output of the run: <section data-remote="catalog"><h2>Catalog for Asha</h2></section><section data-remote="checkout"><button>Pay</button></section><section data-remote="broken">This section is unavailable: remote failed to load</section> host received checkout:done
Key points
- Micro-frontends give team and deployment independence at the cost of complexity.
- Integration options are packages, run-time federation or ES modules, iframes and server composition.
- A mount and unmount contract plus events keeps remotes decoupled.
- Share React as a singleton or isolate remotes. Control CSS leakage and version skew.
- A monorepo with feature folders is often enough.
Common mistakes
- Loading two copies of React and breaking hooks across the boundary.
- Sharing mutable global state between remotes instead of an event contract.
- No error boundary or fallback around remotes.
- Choosing micro-frontends for a small team that could use one codebase.
- Letting remotes leak CSS into each other.
Follow-ups
- How does Module Federation share React as a singleton?
- How would you share authentication and routing between remotes?
- How would you test the integration between the shell and a remote?
Tips
- Lead with the team and deployment reasons. Technology is second.
- Describe a concrete contract. It shows real design thinking.
- Offer the monorepo alternative to show judgment.