What is the Module Federation and how does it apply to Node.js?

Why Interviewers Ask This

Advanced questions like this reveal whether a candidate has internalized Node.js deeply enough to make architectural decisions. Strong answers demonstrate both breadth and depth of experience.

Answer

Module Federation is a Webpack 5 feature primarily used in frontend microfrontend architectures — it allows separately built JavaScript applications to share code at runtime. While it originated on the frontend, it applies to Node.js in specific scenarios. In Node.js microservices, you can use Module Federation to share common code (shared utilities, validation schemas, TypeScript types, API client SDKs) between services at runtime without duplicating the code in each service's bundle. A host application can dynamically load remote modules from other services at runtime: const remoteModule = await import("remoteApp/sharedUtils");. This avoids the need to publish and version shared packages to npm for internal modules that change frequently. However, for most Node.js applications, npm workspaces or monorepos (Turborepo, Nx) are more practical approaches to sharing code between services without the runtime complexity of Module Federation. Module Federation in Node.js is most relevant in large, rapidly evolving microservice ecosystems where teams need truly independent deployments with shared runtime dependencies.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Node.js codebase.