跪拜 Guibai
← Back to the summary

Three Years of Micro-Frontends Ended in a Monolith: Load Time Down 800ms, Dev Efficiency Up 2x

Title: After Three Years of Micro-Frontends, We Finally Split It into a Monolith

Author: 涛涛ing

Tags: Frontend

Last week, with the final sub-app's code merged into the main repository, we finally dismantled the three-year-old micro-frontend architecture into a single monolith.

There were no release incidents, no performance regression—on the contrary, first-paint time on the web dropped by 800ms, and R&D efficiency doubled.

Looking at the Git commit log, I let out a long sigh of relief. Three years ago, as a key member of the architecture group, I hand-built this micro-frontend system with qiankun. My presentation back then was polished: "Tech stack decoupling, independent deployment, team autonomy, fault isolation."

Three years later, tearing it down was the best decision I made for this project.

Today I'm not going to talk about how to configure micro-frontends. I want to talk about how we were gradually driven crazy by the concept.

1. Micro-frontends are not a silver bullet but an "organizational patch"

Let me ask a soul-searching question: Why do you want to use micro-frontends?

Our reason back then: the company had three business lines, using Vue2, Vue3, and React respectively. Three teams had to work in one unified Admin dashboard. iframe gave a poor experience; forcing a single tech stack would cost too much migration effort.

So micro-frontends became the perfect "compromise."

But that was exactly the start of the disaster. Because micro-frontends are essentially not a pure technical optimization, but an "organizational patch." They solve the problem of "how multiple teams write code in one page without fighting." But to achieve that, they introduce horrifying technical complexity.

2. The "Three Original Sins" of micro-frontend architecture

Sin 1: Unfixable "style pollution"

Think enabling qiankun's sandbox isolates styles? Too naive.

The real scenario: The main app uses Ant Design, sub-app A uses Element Plus, and sub-app B hand-written CSS.

One day, the main app needs a global Modal confirmation dialog. Sub-app A's global style contains:

.modal { z-index: 100 !important; }

This directly caused the main app's modal to be pushed down, users couldn't click the button, and online complaints exploded.

How did we finally solve it? We not only enabled strictStyleIsolation (which completely changes sub-app DOM structure and breaks many originally working components), but also hard-coded a pile of z-index: 9999999 patches in the main app. Micro-frontends didn't decouple; they turned styling into hell.

Sin 2: Terrible "communication and state sharing"

One of the biggest micro-frontend challenges: how does the main app pass user info to sub-apps?

Officially recommended approaches are initGlobalState or props-based passing. Sounds nice, right? But sub-apps are independently deployed and sometimes need to run standalone for debugging, meaning they must work in both "with main app" and "without main app" environments.

So for user authentication, we wrote four entirely different adapter logics across the main app and three sub-apps.

Even worse was cross-app data interaction. An action in sub-app A needed to refresh a table in sub-app B. This "cross-app communication" eventually turned into screens full of EventBus and global variables. You think you're building micro-frontends, but you're actually building the worst kind of distributed communication in microservice architecture.

Sin 3: Desperate "dependency hell" and package size

One original goal of micro-frontends was to split a large app into smaller pieces. In reality, each sub-app bundles independently.

The main app imports lodash once, sub-app A imports lodash again, sub-app B imports it once more. Plus each has its own Vue/React runtime. In the end, when a user opens a page, they download three or even four complete sets of underlying dependencies. First-screen JS size increases rather than decreases.

You might say, configure externals to share dependencies. I did. Then the main app upgraded Vue once, and sub-app A went blank due to dependency incompatibility.

3. Why I eventually decided to "reverse course"

The last straw was this year's "cost reduction and efficiency improvement."

Business changed, and the original three frontend teams merged into one large group. With the organizational change, the prerequisite of "team autonomy" instantly vanished.

Once the "people" problem was solved, the technical cost of micro-frontends became glaring:

Without a strong cross-team, cross-stack requirement, micro-frontends are pure self-harm.

So we started refactoring. We extracted business code from each sub-app and merged it into a single repository based on the latest Vue3 + Vite. All state sharing became a simple Pinia store, style conflicts were resolved with Scoped CSS, and component reuse was extracted into an internal packages/ui.

The whole world became quiet.

4. A word of advice for those about to adopt micro-frontends

This post isn't a wholesale rejection of micro-frontends. If you're at Alibaba, ByteDance, or similar scale, with hundreds of frontend developers working concurrently on dozens of admin systems, micro-frontends are indeed the only solution.

But if you're in a small or medium company, or just a frontend team of dozens, listen to my advice:

  1. Whatever can be solved with npm packages, never use micro-frontends. If you just need to reuse a few components or pages, publish an NPM package or manage multiple packages with Monorepo—the cost is more than an order of magnitude lower.
  2. Whatever can be solved with iframe, you can also use iframe. Often, the cost of forcibly unifying the experience far exceeds the minor fragmentation iframe brings.
  3. Don't drag the company's architecture group into it just because you want it on your resume. You'll be happy, but the people who inherit it will curse you for a lifetime.

Micro-frontends are for solving organizational architecture problems. Technology itself is neither good nor bad, but used in the wrong place, it becomes a disaster for every frontend developer.

Comments

Top 3 from juejin.cn, machine-translated. The original thread is authoritative.

组合搭配函数

After running it for three years and then splitting it back, that decision takes some guts. The first screen getting faster says it all. With version drift and duplicate dependencies, micro-frontends really don't add up cost-wise.

不服老的小黑哥

That's true. A lot of the time it's just micro-frontends for the sake of micro-frontends.

彬彬有礼5520

Like