Frontend System Design · Lesson 37 of 86 · 4 min
Micro-Frontends: Core Principles
In an interview, you'll be asked to justify the complexity of micro-frontends. Your answer must center on two principles: independent deployment and technology agnosticism.
Micro-frontends are a solution to an organizational scaling problem. They exist to let large numbers of developers, working in separate teams, ship features for a single application without stepping on each other's toes. If you aren't solving that problem, a monolith is simpler and better.
When you propose this architecture, you are trading technical simplicity for organizational velocity. The interviewer wants to see that you understand this trade-off. The entire pattern is built on two core ideas that enable this velocity.
Principle 1: Independent Deployment
Each micro-frontend must be buildable, testable, and deployable to production independently. A change in the "product-details" micro-frontend should not require a rebuild or redeployment of the "shopping-cart" micro-frontend.
This is the primary benefit. It allows teams to release features on their own schedule. It decouples release cycles, reduces coordination overhead, and isolates risk. If one team's deployment fails, it can be rolled back without affecting the rest of the application.
This is achieved through separate CI/CD pipelines, typically triggered by changes in a specific part of a monorepo or in a dedicated repository for that micro-frontend.
# .github/workflows/deploy-product-listing.yml
name: Deploy Product Listing Micro-frontend
on:
push:
branches:
- main
# Trigger this workflow ONLY on changes within this micro-frontend's directory
paths:
- 'packages/product-listing/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install, Build, and Test
run: |
cd packages/product-listing
npm ci
npm run build
npm run test
- name: Deploy to CDN
run: |
# This step uploads the built bundle(s) to a static host like S3 or a CDN.
# The container app will load this artifact by a specific versioned URL.
echo "Deploying build artifacts..."
# Example: aws s3 sync ./dist s3://my-mfs/product-listing/v1.2.3
This separation is the key to team autonomy.
In an interview, frame this as a business advantage. "Independent deployment allows us to ship value to customers faster. A bug fix in the checkout flow doesn't have to wait for a feature freeze in the product search team. It reduces risk and shortens the feedback loop."
Principle 2: Technology Agnosticism
Different micro-frontends can be built with different technology stacks. One team can use React, another Vue, and a third can use Svelte or even vanilla JavaScript. A team can also upgrade its part of the application to a new version of a framework (e.g., React 18 to 19) without forcing every other team to upgrade.
This is a powerful feature, but it's also where the biggest risks lie.
The main reasons to leverage this are:
- Incremental Migration: You can strangle a legacy monolith by building new features as micro-frontends in a modern stack. This avoids a high-risk, all-or-nothing rewrite.
- Team Expertise: It allows teams to use the tools they are most productive with, or the best tool for a specific job.
Here is a simplified view of how a container application might load two micro-frontends built with different frameworks.
<!DOCTYPE html>
<html>
<head>
<title>Micro-Frontend Shell</title>
</head>
<body>
<h1>Our E-Commerce Site</h1>
<!-- Mount points for each micro-frontend -->
<div id="product-listing-container"></div>
<div id="shopping-cart-container"></div>
<!--
In a real system, a script here (the "shell" or "orchestrator")
would dynamically fetch and mount the micro-frontend bundles.
This might use a library like single-spa or a runtime mechanism
like Webpack Module Federation.
-->
<script>
function mountMicroFrontend(containerId, bundleUrl, mountFnName) {
const script = document.createElement('script');
script.src = bundleUrl;
script.onload = () => {
// Each micro-frontend exposes a global function to render itself
if (window[mountFnName]) {
window[mountFnName](document.getElementById(containerId));
}
};
document.body.appendChild(script);
}
document.addEventListener('DOMContentLoaded', () => {
mountMicroFrontend(
'product-listing-container',
'https://cdn.myapp.com/product-listing/v1.2.3/main.js', // React bundle
'mountProductListing'
);
mountMicroFrontend(
'shopping-cart-container',
'https://cdn.myapp.com/shopping-cart/v2.1.0/main.js', // Vue bundle
'mountShoppingCart'
);
});
</script>
</body>
</html>
The trap: Candidates often praise technology agnosticism without acknowledging the costs. An interviewer will immediately probe on this. Be prepared to discuss two major drawbacks:
- Bundle Size: If the React team ships React and the Vue team ships Vue, you're sending two frameworks down to the user. This gets worse with shared utilities like
lodashordate-fns. The solution involves externalizing common dependencies via tools like Webpack Module Federation'ssharedconfig, import maps, or a global UMD build loaded by the shell. - Inconsistent User Experience: Different teams using different component libraries can lead to a disjointed, Frankenstein-like UI. The solution is a robust, framework-agnostic design system. All teams must consume the same design tokens (colors, spacing, typography) and ideally use a shared library of web components or framework-specific wrappers around a core component set.
The Trade-offs You Must Name
When you advocate for micro-frontends, you are also signing up for their complexity. You must be the first one to bring up the downsides in an interview.
- Operational Complexity: You now have N repositories, N build pipelines, and N deployments to manage. Versioning, rollback, and monitoring become more complex.
- UX Fragmentation: Maintaining a consistent look and feel requires strong governance and a mature design system. Without it, the app feels broken.
- Cross-Cutting Concerns: How do you handle authentication, routing, internationalization, and analytics consistently? These are typically owned by the container application (the "shell"), which provides APIs for the micro-frontends to use.
- Inter-App Communication: How does the "add to cart" button in the
product-listingmicro-frontend update theshopping-cartmicro-frontend? This requires a clear contract, often using Custom Events on thewindowobject, a shared event bus, or passing callbacks from the shell.
Acknowledging these challenges shows you have a realistic understanding of the architecture, not just a theoretical one.
Try it
In 15 minutes, sketch out a plan for a team that wants to migrate a large, legacy jQuery e-commerce site to React. They can't afford a full rewrite. How would you use the principles of micro-frontends to allow them to build the new "Product Detail Page" in React while the rest of the site remains in jQuery? Focus on how you would ensure independent deployment and handle the technology mix on a single page.
Next: We will cover the specific patterns for making these independent parts work together in Micro-Frontend Integration Strategies.
Lock it in — apply this lesson under interview conditions.