Skip to content

Lesson 3 of 9 · 26m

Composition Strategies: Build-Time, Server, Client, and Islands

Compare the real composition models — npm packages, edge/server includes, runtime federation, iframes, and web components — by isolation, UX, and operational cost.

"Micro-frontends" is not one architecture. It is a family of composition strategies with radically different tradeoffs. Most production systems mix two or three of them. Your job is not to pick the fashionable one; it is to pick the weakest isolation that still solves the organizational problem.

Build-time composition: the boring baseline

Publish slices as versioned npm packages and compose them in one application build.

{"dependencies": {"@acme/checkout-ui": "2.8.1", "@acme/search-ui": "4.3.0"}}

This is operationally simple, type-safe, and easy to test. It is also not independently deployable: every package update still requires a shell release. Use it when ownership boundaries matter more than deployment autonomy. Many teams should stop here.

Server-side composition

A shell server or edge layer assembles HTML fragments:

<main><!--#include virtual="/fragments/search-header" --><!--#include virtual="/fragments/product-detail?sku=SKU-1842" --></main>

Modern versions use edge functions, reverse proxies, or fragment services rather than literal SSI. The strength is first paint and resilience: fragments can stream in and fail independently. The weakness is interaction orchestration once the page hydrates.

Client-side runtime composition

The shell loads remote JavaScript modules in the browser. Module Federation made this mainstream:

// webpack.config.js in the shell
new ModuleFederationPlugin({
  name: "shell",
  remotes: { checkout: "checkout@https://cdn.acme.io/checkout/remoteEntry.js" },
  shared: { react: { singleton: true, requiredVersion: "^19.1.0" } },
});

This is powerful because remotes deploy independently. It is dangerous because the browser becomes a distributed runtime: version skew, shared singletons, and loading failures are now user-visible concerns.

Iframes and web components

Iframes are unfashionable and extremely effective when hard isolation matters: payment widgets, untrusted embedded tools, legacy applications. You get process, style, and security boundaries for free, then pay in layout coordination, focus management, and awkward communication.

Web components are a neutral interface, not a framework migration plan:

<checkout-cart cart-id="crt_92fj" locale="en-US"></checkout-cart>

They work well as integration points because the shell only depends on the element contract, not the framework inside.

Choose by failure mode

Ask what must remain true when a slice fails. If recommendations can disappear, runtime composition is fine. If checkout must render perfectly, isolate it more aggressively. If all slices must ship atomically, build-time composition is probably enough.

Field notes

  • Most estates need a mixture: server composition for page shells, runtime composition for autonomous applications, iframes for hard trust boundaries.
  • Runtime JavaScript integration is a distributed-systems problem, not just a bundler feature.
  • Web components expose contracts; they do not solve dependency, routing, or state ownership for you.
  • Choose the least powerful composition model that solves the coordination problem you actually have.

Was this lesson helpful?

Sign in to rate