Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 8

Micro-Frontends: When and How to Deconstruct Your UI

Recommended resources

Welcome back. In our last lesson, we explored repository strategies, contrasting the unified approach of a monorepo with the distributed nature of polyrepos. We established that this choice is fundamentally about optimizing for developer collaboration and managing code dependencies. Now, we shift our focus from how code is organized to how it is built, deployed, and run, tackling one of the most significant architectural patterns in modern frontend development: micro-frontends.

This lesson directly addresses the core interview question of when and why to break apart a large monolithic frontend. For a senior engineer, simply knowing how to implement a micro-frontend isn't enough; you must deeply understand the organizational problems they solve and the substantial complexity they introduce. Mastering this topic demonstrates your ability to think beyond code and make strategic decisions that impact team autonomy, deployment velocity, and the long-term health of the entire engineering organization.

From Monolith to Micro-Frontend: A Shift in Philosophy

Let's begin by solidifying our understanding of the two opposing architectural styles. A monolithic frontend is what you're likely most familiar with: a single, large application where all features, routes, and components live in one codebase, are built together, and deployed as a single unit. Think of it as a large department store—everything is under one roof, managed by a central authority.

This diagram uses the analogy of a department store versus a shopping mall to illustrate the difference between a monolithic frontend and a micro-frontend architecture. The monolith is a single, self-contained unit, while the micro-frontend approach consists of multiple independent applications (stores) composed within a larger host application (the mall).

A micro-frontend (MFE) architecture, in contrast, breaks this single application into a collection of smaller, independently deployable applications. These are then composed together in the browser to create a cohesive user experience. In our analogy, this is the shopping mall: a host structure contains multiple independent stores (Nike, Apple), each with its own staff, inventory, and operations, but all sharing the mall's infrastructure.

The core benefit, and the primary reason for adopting MFEs, is independent deployment. This allows different teams to ship their part of the application without coordinating with, or being blocked by, other teams.

This diagram contrasts the development and deployment workflow of a monolith with that of a micro-frontend. In a monolith, all components are bundled and deployed as one application. In a micro-frontend architecture, each component is a separate micro-application with its own codebase and CI/CD pipeline, allowing for independent deployments that are composed into a final product.

The "Why": Solving Organizational Pain, Not Technical Problems

The most common mistake engineers make is seeing MFEs as a purely technical solution to problems like large bundle sizes or slow build times. While MFEs can influence these, those issues are often better solved within a well-structured monolith using techniques like code-splitting and build caching (as we discussed with Turborepo/Nx).

The real driver for MFEs is organizational scaling pain. The following article does an excellent job of defining both architectures and identifying the pain points that signal a monolith is no longer serving your organization.

Frontend System Design: Micro Frontends, Monolith vs MFE

This article provides a clear introduction to monolithic frontends and micro-frontends, emphasizing the core principles and organizational problems they address.

First, read the section on Monolithic Architecture to understand its characteristics and, more importantly, its pain points at scale. Next, read What Are Micro-Frontends? Focus on the concept of "Vertical Slices"—this is a critical concept where teams own an entire feature end-to-end. Finally, study the Tradeoffs section. Pay close attention to the "Inflection Point" graph and the explicit criteria for when to choose (and when not to choose) MFEs.

The key takeaway is that you should only consider MFEs when the coordination cost of your monolith becomes unbearable. Ask yourself these questions, which are taken directly from real-world breaking points:

  1. Is your CI/CD pipeline a bottleneck? If a simple change requires a 30-45 minute build and test cycle for the entire application, your development velocity is being throttled.
  2. Are teams constantly blocking each other? If the "Checkout" team has to wait for the "Search" team to fix a failing test before they can deploy a critical bugfix, your monolithic pipeline is creating organizational conflict.
  3. Is deployment risk unacceptably high? If a bug in a minor, non-critical feature (e.g., a marketing banner) can take down the entire application (including the checkout flow), your blast radius is too large.

If the answer to these is "yes," you have a genuine organizational problem that MFEs are designed to solve. As Luca Mezzalira from DAZN explains, this scaling challenge is precisely what pushes large organizations toward this architecture.

Lessons from DAZN: Scaling Your Project with Micro-Frontends

In this talk, Luca Mezzalira, a principal architect, discusses the journey from a monolith to micro-frontends at DAZN, a large-scale streaming service.

Watch the segment from the beginning, where he explains why a monolith is the right starting point but fails as the team and complexity scale. Then, watch his definition of MFEs and their core principles, which are modeled directly on the principles of microservices but adapted for the frontend.


The "How": A Spectrum of Integration Strategies

Once you've decided that MFEs are necessary, the next question is how to compose these independent applications. There isn't a single way; it's a spectrum of choices, each with significant trade-offs between isolation, performance, and complexity.

This table from the DEV Community article provides a great overview of the main strategies.

Frontend System Design: Micro Frontends, Monolith vs MFE

This section of the article details the various technical strategies for composing micro-frontends and summarizes their trade-offs.

Please read the entire section on Composition Approaches. Focus on understanding the pros and cons of each method presented in the Comparison Matrix. Most importantly, internalize the "Three Underlying Tensions" at the end: Coupling vs. Autonomy, Isolation vs. Shared Resources, and Performance vs. Flexibility.

Let's summarize the key runtime strategies:

  • Iframes: The oldest method. They offer perfect isolation (CSS, JS, and the DOM are completely separate), but at a high cost. They are heavy, create a poor user experience (e.g., managing scrolling, resizing), and make communication between MFEs clumsy via postMessage. Use them for integrating third-party widgets where you have zero trust.
  • JavaScript Integration (Single-SPA style): A host application dynamically loads a JavaScript bundle from another MFE. The MFE bundle exposes a mount function that the host calls to render the component into a specific DOM element. This gives you independent deployment but requires manual management of shared dependencies to avoid loading React five times.
  • Module Federation (Webpack 5+): This is the dominant modern approach, especially in the React ecosystem. It allows an application to dynamically load code from another, separately deployed application at runtime, while intelligently sharing dependencies. Think of it as "npm at runtime." It solves the "duplicate React" problem of the classic JavaScript integration approach.

For a senior-level interview, having a solid grasp of Module Federation is frequently expected. It's a powerful tool, but it comes with its own set of complexities and common misunderstandings.

Deep Dive: Webpack Module Federation

Module Federation is not magic. It's a clever transport layer for code, but it doesn't automatically solve problems like state management or API contract versioning. The following video from Jack Herrington is an outstanding resource for understanding the common mistakes engineers make when adopting it.

Five Module Federation/Micro-Frontend Mistakes

This video masterfully debunks the five most common misconceptions about Module Federation and micro-frontends. Watching this will equip you to answer deep-dive interview questions with nuance and precision.

Watch the entire video. Each point is critical for a senior-level understanding: MFE vs. Module Federation: They are not the same. MFE is an architecture; Module Federation is a tool that helps enable it. Implicit State Sharing: A huge misconception. Module Federation shares code, not state. Two federated counter components will have separate states. Availability Risk: What happens if the remote server goes down? He shows why this isn't the concern you think it is (you deploy to static storage like S3, not a live server). Versioning: There is no built-in versioning. A breaking change in a remote MFE can crash the host. He demonstrates how to use Error Boundaries as a critical mitigation strategy. TypeScript & Type Safety: Federated modules are just JavaScript at runtime; they lose their types. He demonstrates a robust pattern using a shared library to maintain type contracts between the host and remote.


The Pragmatic Middle Ground: Modular Monoliths and Next.js Multi-Zones

For many organizations, a full-blown micro-frontend architecture is premature optimization. Given your experience with Next.js, it's crucial to know the patterns that provide some of the benefits of MFEs without incurring all the complexity. The "Modular Monolith" is a powerful intermediate step.

A Modular Monolith uses a monorepo (with tools like Turborepo) to enforce strict boundaries between different parts of the application at the code level. You still deploy a single application, but the tooling ensures the "Search" module cannot improperly import code from the "Checkout" module. This cleans up your architecture and can significantly improve build times via caching, often solving the immediate pain points without the overhead of a distributed system.

For organizations that truly need independent deployments, Vercel (the company behind Next.js) offers a native solution called Multi-Zones.

Micro-Frontends vs Monoliths in Next.js 15: The Brutally Honest Guide [Stop Splitting Too Early] | Daily Dev Post

This article provides a refreshingly honest and pragmatic perspective, tailored specifically for Next.js developers. It cuts through the hype and offers concrete advice.

Start with the Quick Summary and native support section to get the main thesis. Read When to use micro frontends to see the "Hard Blockers" that justify the move. Study the Multi-Zones example. This is the official "Golden Path" for MFEs in the Next.js ecosystem. Finally, understand the Modular Monolith concept. This "Multi-Zone Monorepo" is the sweet spot for many growing companies.

The Multi-Zones approach uses a gateway Next.js app that intelligently rewrites traffic to other, completely independent Next.js apps based on the URL path. For example, requests to /blog/* are proxied to the blog-app, while requests to /shop/* go to the shop-app. This achieves true independent deployment for different teams while presenting a single, unified domain to the user.


Trade-Off Analysis

Let's consolidate our findings. When an interviewer asks you to compare these approaches, they are testing your ability to analyze trade-offs.

Dimension Monolith Modular Monolith (Monorepo) Micro-Frontends (Module Federation)
Team Scalability Low. Prone to merge conflicts and ownership ambiguity. Medium. Enforces code boundaries but still a single deployment pipeline. High. Autonomous teams own their full stack.
Deployment All-or-nothing. A small change requires a full app deployment. All-or-nothing, but with faster, smarter builds via caching. Independent. Teams can deploy on their own cadence.
Build Time Slow. Grows linearly with the size of the codebase. Fast. Only builds what has changed. Very Fast. Each MFE has a small, isolated build.
Code Refactoring Easy. A single find-and-replace operation. Easy. Atomic commits across the monorepo. Hard. Requires coordination across multiple teams/repos.
Operational Cost Low. One CI/CD pipeline, one server to monitor. Medium. Requires sophisticated monorepo tooling. High. Multiple pipelines, complex orchestration, distributed monitoring.
Performance High. Can be optimized into a single, streamlined bundle. High. Same as monolith. Medium. Risk of dependency duplication and network latency for loading remotes.
Best For Small teams, MVPs, projects with < 20 engineers. Growing teams (20-50 engineers) feeling monolith pain but not ready for full MFE complexity. Large organizations (50+ engineers) with autonomous teams and clear domain boundaries.

Conclusion: Key Takeaways

Choosing between a monolith and micro-frontends is a high-stakes architectural decision. A senior engineer must be able to justify their choice based on organizational context, not technical trends.

  • Monolith First: Start with a monolith. It is simpler, faster, and the right choice for the vast majority of projects. Do not introduce the complexity of a distributed system until you have a genuine distributed team problem.
  • MFE is an Organizational Pattern: Adopt MFEs to solve problems of team autonomy and deployment bottlenecks, not just to fix slow builds. The primary benefit is independent deployment.
  • Know the Integration Strategies: Understand the trade-offs between iframes, JavaScript injection, and Module Federation. For modern React apps, Module Federation is the key pattern to understand deeply.
  • Master Module Federation's Pitfalls: Be prepared to discuss how to handle its lack of state sharing, versioning (Error Boundaries), availability (static deployment), and type safety (shared type packages).
  • Consider the Middle Ground: For many growing applications, a "Modular Monolith" in a monorepo or a "Multi-Zone" architecture in Next.js offers a more pragmatic path to scaling than a full-blown, client-composed MFE architecture.

In our next lesson, we will dive into Networking & Data Fetching Architecture. Whether your frontend is a monolith or composed of many micro-frontends, it needs to efficiently communicate with backend services. We will explore the trade-offs between REST, GraphQL, and tRPC, and examine patterns like the Backend-for-Frontend (BFF), which often becomes a critical piece of a micro-frontend ecosystem.