When should you leverage Module Federation, and how?

Zack Jackson
11 min readFeb 2, 2022

Critical thinking and patterns on when, why, where, to leverage Module Federation from the creator of the technology.

Webpack’s Federation is immensely useful if used properly.

The tricky part is there's not much information on how and where to leverage the technology. Leading to a bit of a wild west scenario. I've been working with the technology for almost 2 years now, in that time — I've uncovered a handful of patterns and considerations that should be taken into account when developing applications at scale.

For this article, I am only going to focus on Module Federation in the frontend. Getting into federated backends is a whole other story.

Module Federation

When to use it?

The primary use case for federation would be an uncoordinated distribution of software at runtime. There are a couple of categories that can fit nicely into Module Federation.

Global Components like Header or Footer are great first candidates as they are usually unanimous across an application, relatively self-contained, and ideally need to remain consistent across all applications. Updating your Header, publishing it to NPM, then turning around and installing it into 5–10–15 separate applications, and deploying them gets tiresome real fast. It's also a massive waste of time since it probably takes 20–30 min to actually get through both build and deploy pipelines. So testing in a staging environment is painful and rolling it out across all consumers is laborious.

Features owned by another team that appears across multiple user flows or applications. This is a double edge sword, however. You shouldn't just arbitrarily federate modules between apps without something like a “Component Level Ownership” model.

Horizontal enablement teams like AB testing, Analytics, or Platform Teams can all benefit from the ease of at-runtime orchestration. These Teams also tend to stick to a small API surface with good contracts and code that for the most part — runs in a self-sustaining manner. Making them perfect for Federation.

Systems Migration and Advanced Architecture are the most beneficial aspects I’ve Encounters where federation has been…

--

--

Zack Jackson

Infra Architect @ ByteDance. Creator of Module Federation. Specializing in Bundler and Javascript Orchestration at scale.