Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
39

Frontend System Design · Lesson 39 of 86 · 4 min

Communication Between Micro-Frontends

In an interview, this topic tests your understanding of distributed systems principles on the client side. Your answer shows whether you can design for loose coupling or if you'd accidentally build a distributed monolith.

When your micro-frontends need to interact, you have to enable that communication without destroying the isolation that made you choose them in the first place. The goal is to create explicit, well-defined contracts between them, not a tangled web of direct dependencies.

There are four main patterns. You need to know the trade-offs for each.

1. Use Browser Events for Simple, Local Communication

This is the most straightforward approach. You use the browser's built-in eventing system.

Custom Events are for micro-frontends running in the same browser window and on the same origin. One micro-frontend dispatches a CustomEvent on a shared DOM element, typically window or document, and others listen for it.

It's simple, decoupled, and requires no external libraries. Use it for simple notifications, like a "product added to cart" event fired by a product page, which a header micro-frontend listens to in order to update a cart icon.

window.postMessage() is for when your micro-frontends are in different browser contexts, most commonly an iframe. This is the only secure way to communicate across different origins on the client.

Your interviewer is listening for two words: "origin validation". When you receive a message, you must check the event.origin property to ensure the message is from a trusted source. When you send a message, you must specify the target origin. Omitting this is a critical security flaw and a major red flag in an interview.

2. Implement a Pub/Sub Bus for Application-Wide Events

For more complex applications, relying on raw DOM events can become chaotic. It's hard to track what events exist, who is firing them, and who is listening.

A global Pub/Sub (Publish/Subscribe) event bus solves this. It's a simple, centralized module that micro-frontends can import. Instead of dispatching events on the window, they publish named events to the bus. Other micro-frontends subscribe to those events.

This pattern formalizes the communication. It gives you a single place to log, debug, or even middleware events. It decouples senders from receivers; a publisher doesn't know or care who is subscribed.

Here is a minimal implementation. This is all you need to explain the concept.

// --- Global Event Bus (shared module) ---
class EventBus {
  private subscribers: { [key: string]: Function[] } = {};

  on(eventName: string, callback: Function) {
    if (!this.subscribers[eventName]) {
      this.subscribers[eventName] = [];
    }
    this.subscribers[eventName].push(callback);
  }

  emit(eventName: string, data?: any) {
    if (!this.subscribers[eventName]) return;
    this.subscribers[eventName].forEach(callback => callback(data));
  }
}
export const globalEventBus = new EventBus();

// --- Micro-frontend A (e.g., Authentication) ---
import { globalEventBus } from './event-bus';

function login(user: { name: string }) {
  // ...login logic
  globalEventBus.emit('auth:user-logged-in', user);
}

// --- Micro-frontend B (e.g., Header) ---
import { globalEventBus } from './event-bus';

globalEventBus.on('auth:user-logged-in', (user: { name: string }) => {
  console.log(`Updating header to show welcome message for ${user.name}`);
  // document.getElementById('user-display').textContent = `Welcome, ${user.name}`;
});

The trap: Don't let your event bus become a dumping ground for complex state. It's for transient events, not for state management. An event should announce that something happened, not transfer the entire application state in its payload.

3. Use the URL for State and Navigation

The URL is the most robust and naturally decoupled communication channel you have. It's global, user-visible, and bookmarkable.

Use the URL to communicate page-level state. When a user clicks an item in a list, navigate to a new URL like /products/123. The product detail micro-frontend can then read the ID from the URL and fetch its own data.

This completely decouples the list from the detail view. The list micro-frontend doesn't need to know anything about the detail micro-frontend, only how to construct a URL.

This is the best pattern for cross-micro-frontend navigation and for passing small, public identifiers.

4. Use Shared State as a Last Resort

Sometimes, you have a piece of state that is truly global and fundamental, like user authentication status or the current theme. Forcing this through events can be cumbersome.

In these rare cases, you can use a shared library or state management module (like a tiny Zustand store or a simple context provider). The key is to keep this shared surface area as small as humanly possible.

The trap: Proposing a single, monolithic Redux store for all micro-frontends. This is an anti-pattern that recreates the tightly coupled monolith you were trying to escape. If you share state, share only the atoms of state that are absolutely necessary, and keep the logic for updating that state isolated. For example, only the auth micro-frontend should be able to update the user's auth status in the shared store.

Try it

Implement a simple EventBus class like the one above in a single file. Create two functions that simulate micro-frontends. Have one function publish a theme:changed event with a payload { theme: 'dark' }. Have the second function subscribe to that event and log the received payload to the console.

Next: Micro-Frontends: Pros and Cons for Large Teams

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Micro-Frontend Integration Strategies

Next

Micro-Frontends: Pros and Cons for Large Teams