VOOZH about

URL: https://dev.to/dhinesh_ks_9db13f15d64f7/micro-frontends-the-hidden-code-sharing-problem-4j90

โ‡ฑ The Hidden Code Sharing Problem in Micro Frontends - DEV Community


How teams go from copy-paste chaos โ†’ internal npm packages โ†’ a monorepo that finally makes sense.

๐Ÿ‘ Hero Image


โšก TL;DR: Micro frontends help teams move independently, but they also make code sharing harder than it looks. Internal npm packages can solve part of the problem, but they often add publishing and versioning overhead. A monorepo offers the same reuse with much less maintenance.


๐Ÿงฉ The Scale Problem with Micro Frontends

As frontend applications grow, teams break large apps into micro frontends โ€” so different parts of the product can evolve independently.

In an ecommerce platform, that might look like:

App Responsibility
๐Ÿ” Auth Login, signup, session
๐Ÿ›๏ธ Product Catalog Listings, search, details
๐Ÿ›’ Cart & Checkout Cart state, payments
๐Ÿ‘ค Account / Settings Profile, preferences

This works great for team autonomy โ€” different teams own, ship, and evolve their pieces without blocking each other. ๐Ÿš€

But as the number of MFEs grows, a problem quietly emerges:

โš ๏ธ The hidden cost: Even though apps are split, they still rely on the same shared building blocks โ€” formatters, API clients, hooks, types, business logic. Managing that shared code across repos is harder than it looks.

The shared building blocks typically include:

// Common code every MFE needs
price & currency formatters
API request helpers
shared product and user types
auth / session utilities
analytics tracking helpers
reusable hooks // useCart(), useAuth(), useDebounce()
business logic // discounts, tax, inventory checks

This is where things start getting messy. Teams solve it in one of two ways โ€” and both have downsides.


๐Ÿ“ฆ The Polyrepo + npm Package Approach

In a polyrepo setup, apps live in separate repositories:

auth-app/
product-catalog-app/
cart-checkout-app/
account-app/

To avoid duplication, shared code gets extracted into internal packages:

shared-ui/
shared-hooks/
shared-utils/
shared-types/
api-client/

โœ… This is definitely better than copy-paste. Shared code is reusable and has clean boundaries.

The Release Friction Problem

But over time, a different kind of overhead creeps in. Even a small shared change now requires this entire workflow:

1. Update the shared package
 โ†“
2. Raise a PR & get it reviewed
 โ†“
3. Publish a new version to npm
 โ†“
4. Bump dependencies in all consuming apps
 โ†“
5. Retest each app independently
 โ†“
6. Release everything separately

๐Ÿ˜“ That's a lot of process for changing one helper or one hook. As shared code grows, teams end up maintaining not just apps โ€” but a whole ecosystem of internal packages. Code sharing starts feeling heavier than it should.


๐Ÿ—๏ธ What Is a Monorepo?

A monorepo is simply a setup where multiple apps and shared packages live inside the same repository.

apps/
 auth-app/
 product-catalog-app/
 cart-checkout-app/
 account-app/

packages/
 shared-ui/
 shared-hooks/
 shared-utils/
 shared-types/
 api-client/

Apps consume shared code cleanly โ€” just like a regular package, except there's no publish step:

import { Button, Modal } from '@repo/shared-ui'
import { useCart, useAuth } from '@repo/shared-hooks'
import { formatCurrency } from '@repo/shared-utils'
import { apiClient } from '@repo/api-client'
import type { Product } from '@repo/shared-types'

๐Ÿ’ก Key insight: You no longer need to publish every shared abstraction as an npm package just to reuse it. That single change transforms the developer experience.


โœ… How Monorepo Solved the Problem

Once teams move to a monorepo, shared code finally has a natural home. Instead of forcing every reusable piece into a separately published package, code is shared locally through internal workspaces.

The New Workflow

1. Update the shared code
 โ†“
2. All apps use it immediately
 โ†“
3. Test everything together
 โ†“
4. Ship in one PR โœ…

That gives teams the best of both worlds:

โœจ Shared like packages. Managed like one system. Modular code organisation, clean boundaries, reuse across apps โ€” without the publishing and versioning overhead.

Now when a shared utility, hook, or API client changed:

  • All consuming apps could use it immediately
  • Changes could be tested together
  • Refactoring became easier
  • Version drift disappeared

๐ŸŽฏ What Teams Gain

The biggest win isn't just cleaner code โ€” it's less friction in day-to-day development.

๐Ÿงน Less Duplication

Shared code has a clear, single place to live. No more copy-paste divergence.

โšก Faster Development

No more publish-bump-retest cycles for every small shared change.

๐Ÿ”ง Easier Refactoring

Shared code and its consumers can evolve together, atomically.

๐ŸŽฏ Better Consistency

All apps stay aligned on the same implementation, always.

๐Ÿ“‰ Lower Overhead

No more maintaining a growing ecosystem of tiny internal package repos.

๐Ÿ” Better Visibility

One place to search, one place to review, one place to understand the system.


โ˜๏ธ One Important Lesson

Monorepo is powerful โ€” but only when sharing is intentional, not automatic.

Only extract code into a shared package when it is:

  • โœ… Used by two or more apps (not just one)
  • โœ… Valuable to keep consistent across the system
  • โœ… Stable enough to centralise without frequent churn

๐Ÿ“Œ If code is specific to one app, keep it local. Over-extraction creates a different kind of mess โ€” a shared package that nobody quite owns. Intentional sharing is what keeps a monorepo healthy.


๐Ÿ“Š Quick Comparison

Approach Pros Cons
Copy-paste Fast initially Duplication, bugs multiply, inconsistency
Internal npm packages Reusable, modular Publishing overhead, version drift, slow iteration
Monorepo workspaces Reusable + fast iteration + atomic refactors Needs discipline, initial setup cost

๐Ÿ’ญ Final Thoughts

"The best architecture isn't the one with the most packages โ€” it's the one with the least friction."

Micro frontends solve real scaling problems. But as they grow, your code sharing strategy matters just as much as your app boundaries.

A monorepo ends up being the missing piece for most teams โ€” it gives package-style modularity without the publishing overhead, and that makes a huge difference in everyday developer experience. ๐Ÿš€