Micro-Frontends
MFE
Escrito por Darjus Kazakevic · revisado el
Each team ships its own part of the UI; a shell puts them on one page.
Micro-frontends apply the microservices idea to the browser. The team that owns checkout also owns the checkout screens and deploys them on its own schedule. A shell (the container app that loads each team's part) composes the parts into one page. Zalando and IKEA have both described running their shops this way.
It solves one problem: many frontend teams queuing behind one frontend release. The costs reach users directly. Shared libraries can load twice, styles leak between parts, and one slow part slows the whole page. With fewer than about three frontend teams, a well-structured single-page app is cheaper.
En esencia — Cut the UI by business area so each team deploys its own screens, and pay for that freedom with a shell, shared-library rules and heavier pages.
Cuándo recurrir a él
Recurre a él cuando
- Three or more frontend teams queue behind one frontend release
- Teams already own product areas like checkout or search end to end
- An old frontend must be replaced one area at a time
Reconsidéralo cuando
- One or two frontend teams; a well-structured SPA costs far less
- Teams will not agree on shared versions of React and other libraries
- Page weight is critical, for example for users on slow mobile networks
The moving parts
- Vertical team slices
- A team owns one product area, such as checkout or search, from its backend to its screens. Its slice of the UI deploys without the other teams.
- The shell (container app)
- A small app that owns the page frame: routing, layout, sign-in and design tokens. It loads each slice and decides where it appears.
- Composition time
- Slices join the page at build time (npm packages), on the server (edge-side includes), or in the browser at run time (Module Federation, web components, iframes). Only server and run time keep deploys independent.
- Shared dependencies
- Libraries like React must exist once on the page. Teams agree on a version range, and the shell loads one copy as a singleton.
Reglas de diseño
- Agree on shared dependencies up front
- Declare React and its peers as singletons with an agreed version range in the shell. Otherwise each slice ships its own copy, and the user downloads it once per team.
- Split by business area, not by widget
- Give a team a whole area like checkout. Splitting one screen into many small parts owned by different teams multiplies loading and coordination costs.
- Let the shell own the design tokens
- Styles do not respect module boundaries. Each slice ships scoped styles and reads the colours and spacing the shell defines, so one team's CSS cannot restyle another team's page.
- Give every slice a size budget
- One team's large bundle slows everyone's page. Set a JavaScript budget per slice, for example 150 KB gzipped, and fail that slice's build when it goes over.
Errores habituales
- No shared-library agreement, so the page ships three copies of React
- Global CSS in one slice that breaks the layout of another slice
- Slices that call each other's internals, so they must deploy together again
- Adopting it with one frontend team and paying the cost for no gain