EasyMicrofrontends📖 Theory Question

What is Single-SPA and how does it differ from Module Federation?

💡

Hint

Single-SPA is a router/lifecycle orchestrator; Module Federation is a module-sharing mechanism — they solve different layers

Full Answer

Single-SPA is a JavaScript framework that acts as a top-level router for microfrontends. It manages application lifecycle hooks (bootstrap, mount, unmount) and decides which MFE is active based on the URL.

import { registerApplication, start } from 'single-spa';

registerApplication({
  name: '@org/checkout',
  app: () => import('@org/checkout'),
  activeWhen: ['/checkout'],
});

start();

Module Federation (Webpack 5) is a module loading mechanism — it lets one app dynamically import code from another at runtime, sharing dependencies efficiently.

Key differences:

Single-SPAModule Federation
What it solvesRouting & lifecycleModule sharing
Framework-agnosticYesWebpack-only
Dependency sharingNoYes (singleton)
Partial page embeddingHardEasy

They are often used together: Single-SPA orchestrates routing, Module Federation handles runtime code sharing.

More Microfrontends Questions

EasyWhat is a microfrontend and what problem does it solve?EasyHow does Webpack Module Federation work?EasyWhat are the main challenges of microfrontends in production?MediumHow do you share state between microfrontends?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint