Micro-frontends Overview
Estimated Time: 3 hours | Difficulty: Advanced | Prerequisites: Routing, Lazy Loading, Build Process
Module Federation Setup
Using @angular-architects/module-federation
Host (Shell) Configuration
Remote Configuration
Dynamic Remote Loading
Static remote configuration (hardcoded URLs in webpack config) works for development but fails in production where remote URLs differ per environment. Dynamic remote loading solves this by fetching the MFE registry at runtime — typically from a backend API or a configuration file. This means you can add, remove, or update micro-frontends without rebuilding and redeploying the shell application. Think of it like a TV with a channel guide: the TV (shell) does not need to know about every channel at manufacturing time. It downloads the channel list on startup, and new channels can appear without replacing the TV.Shared State & Communication
Shared State Service
Cross-MFE state is the hardest problem in micro-frontend architecture. The temptation is to use a global NgRx store, but that creates tight coupling — the very thing micro-frontends are designed to avoid. The better approach is a minimal shared state service that only holds truly global data (authenticated user, theme, shopping cart) while each MFE manages its own feature state internally.Event Bus for Cross-MFE Communication
An event bus decouples micro-frontends by enabling publish/subscribe communication. The products MFE does not need to know that the header MFE exists — it just emits a “cart:itemAdded” event, and anyone who cares can listen. This is the same pattern as browser DOM events (a button does not know who is listening to its click), applied at the application architecture level.Shared UI Library
Deployment Strategy
Best Practices
Share Wisely
Only share what’s necessary - over-sharing leads to coupling
Version Compatibility
Test shared dependency versions across all MFEs
Consistent Styling
Use a shared design system with CSS custom properties
Error Boundaries
Isolate MFE failures to prevent cascade effects
Next: Nx Monorepo
Scale your Angular projects with Nx monorepo tooling