What are Micro-Frontends and how do they relate to microservices?
Topic: microservices, React Side. Level: Hard.
Answer
Micro-frontends extend the microservices idea to the UI: split a large frontend into independently developed/deployed pieces, each owned by the team that owns the corresponding backend service (vertical, full-stack ownership). Composition can be at build time, run time (Webpack **Module Federation**), or via web components. Benefits: independent deploys and team autonomy. Costs: shared-dependency duplication, styling/consistency challenges, and orchestration complexity — only worth it at large org scale.
```js
// Module Federation: the shell loads a remote micro-frontend at runtime
new ModuleFederationPlugin({
name: 'shell',
remotes: { checkout: 'checkout@https://checkout.example.com/remoteEntry.js' },
shared: { react: { singleton: true }, 'react-dom': { singleton: true } },
})
// const Checkout = React.lazy(() => import('checkout/Cart')) // owned by another team
```