notajson.dev
← All work

case study 03 · lead · multi-portal talent platform · Module Federation, Firebase

Micro-frontends in production

One component library, loaded at runtime by apps that deploy on their own schedules. Most of the hard bugs weren't in the components. They were in caching, sharing and deploys.

// from git and the live hosts

3apps loading the v2 library at runtime
−61%median icon chunk, 6.6 KB → 2.6 KB
4repos that refuse a deploy from the wrong branch

Chunk sizes from like-for-like builds of the library.

Context

The agency, talent and casting apps share one component library through Module Federation. Each app fetches the library's manifest at runtime and loads only the components it uses. A library deploy reaches every app on its users' next page load, with no version pin and no staged rollout. With two other leads, I set the structure of both library generations, and I look after both in production.

Constraints

  • Two library generations are live at once: the older one built on React 18, the newer one on React 19.
  • React, React DOM and Emotion are strict singletons. A version mismatch is a white screen, not a warning.
  • Each app deploys on its own; nothing coordinates a library release with the apps that load it.
  • Test, staging and prod each map to their own branch, in every repo.

Decisions

Open each one for the trade-off behind it.

Firebase rewrites every unknown path to index.html and answers 200. The federation manifest was cached for an hour. After a library redeploy, an app holding the old manifest asked for chunk hashes that no longer existed, got HTML back with a success status, and failed with a ChunkLoadError. CORS was the first suspect, but the host already allowed every origin. The fix was in the hosting config: the manifest and index are never cached, on both library generations.

What I built

  • Cache rules for both library hosts: manifest, stats and index never cached.
  • A branch precheck chained into every deploy command, live on prod in 4 repos.
  • A leaner chunk build: shared JSX and compiler runtimes, and one theme chunk instead of a copy per component.
  • The loaded-first share strategy that lets local apps run against the deployed library.

Result

The live manifest now answers cache-control: no-cache, so a library deploy no longer leaves apps asking for chunks that are gone. The median icon chunk dropped from 6,624 to 2,604 bytes, with one React instance across the share scope. Two things are still open: every component is still its own request, about 150 on the busiest page measured, and hashed chunks are cached for an hour instead of marked immutable.

What I'd do differently

Ship the cache rules with the first deploy. I had them written in July and left them uncommitted; they shipped after the ChunkLoadError reached production in August. A fix isn't done until it's a pull request.