Back

Common Mistakes When Building Microfrontends

 • By Ever Burga

Common Mistakes When Building Microfrontends

Shell and SPA microfrontends served from a CDN: each region of the screen comes from its own versioned path

"Code is a liability, not an asset."

Microfrontends had their flash of popularity more than 10 years ago. Now that they've stepped off the hype train, they haven't become as popular as their backend counterpart.

Still, they remain a relatively common choice in the corporate world. Possibly because of Conway's law and the culture these organizations adopt.

  • mfe: microfrontend
  • ms: microservice
  • shell: host mfe that acts as the orchestrator of the other mfes

Table of Contents

  1. Coupled Remote Loading
  2. Shared Model Corruption
  3. Conclusions

When are remotes loaded?

If we're talking about Angular and Native Federation, we have federation.json files to register the remotes per mfe, and remoteEntry.json to store the asset references.

You'll soon see this turns into a versioning and deployment management problem. This is where the classic blue-green and canary deployment options come in. Each with its own challenges.

(a) for example, we have a shell + SPA mfe application deployed to a CDN.

CDN deployment: v1.2 stacks on top of v1.1 and the browser falls back to v1.1 when v1.2 failsIt works wonderfully. Except for some flickering that hurts CLS, but oh well, you add loading screens. Maybe SSG too for the bots looking for content.

Remotes are loaded from the browser and the requests go to the CDN.

Since keeping a version history costs nothing, retrying is straightforward. The browser remembers that on failure it should retry the last stable version. Either the browser or your CDN.

SSR

In another case, your solution might call for a server deployment.
Various reasons:

  • an extra layer of isolation before reaching the backend
  • SEO+
  • session invalidation due to fraud/timeout/automatic detection

(b) you could deploy everything with SSR

Fully SSR architecture: the shell and each microfrontend are servers with their own replicas

And it would work... and you'd have an architecture that lets you deliver the solution.

But loading microfrontends involves more than your REST interfaces. Loading a remoteEntry.json triggers a cascade of asset requests.

Asset cascade: a staircase while figuring out what to load, then a burst of parallel chunks

And what happens when we do a rollout? Since the Native Federation shell (at least in Angular) does a pre-load every time it starts, we end up with stale memory that invites failures when loading the canary mfe's assets.

Below are two almost comical failures, for blue-green and rollout deployments.

The SSR shell keeps the manifest in memory; after the rollout it still points to chunks that no longer exist

Retrying without affinity: every attempt is a lottery over which version answers the index and each chunk

This is a good moment to ask yourself whether you really need SSR for the whole architecture. Or whether it's enough to have only the shell in SSR, so we go back to the CDN-friendly architecture; you'd just need to share a deploy identifier between the server and the browser, which is simple.
(b.1)

SSR shell with static microfrontends: the shell loads the microfrontend straight from the bucket to render, and the browser then requests that same version through the CDN

And if you really need SSR in the mfes. I don't know, maybe for a video rendering or processing service that shouldn't affect the scaling of other screens, we can use sticky sessions. But this means keeping canary and stable coexisting for longer while the shell is redeployed.

(b.2)

Sticky sessions: v1.2 has its own replicas and a user's index and chunks always come from the same version

Honestly, not a very elegant solution. Maybe you could try storing the deployments in a CDN and also using it as a fallback. The infrastructure complexity grows.

Shared Model Corruption

This is a Domain Driven Design classic.

When you decide to adopt an mfe architecture, you have to be aware that the boundaries between domains harden with much more force than just splitting domains into separate folders or repositories. Now we're even talking about a physical separation in the deployment environment.

That's how you can end up maintaining several implementations of the same class, thinking that, just like when you had a monolith, the cost of fixing the technical debt would be minimal.

A shared component owns the cart and only emits events; each microfrontend rebuilds its own copy its own way and they end up different

It's worth saying that even using AI agents I find this task hard. The advantage of partitioning domains into separate mfes, which lets you put chains on the agents, makes them just as rigid when it comes to refactoring code across domain boundaries.

Conclusions

  • Choosing a software architecture with decoupled development means putting much more detail into upfront planning, since the cost of a mistake multiplies. Not even AI saves us.
  • If you're going to build mfes with SSR... please convince your team not to. Unless it's absolutely necessary. It multiplies the technical difficulty of keeping all the frontends aligned. Also keep in mind that debugging will happen on the server, and you'll have to maintain two sources of errors: the browser and the server.