paint-brush
Optimal Communication Between Microfrontends and Cross-microfrontend Optimizationby@ilyoskhuja
4,953 reads
4,953 reads

Optimal Communication Between Microfrontends and Cross-microfrontend Optimization

by IlyoskhujaFebruary 6th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Micro-frontend architecture is a popular pattern for building large scale web applications. The idea behind it is to split a single application into smaller and independent parts, or micro-frontends, that can be developed, tested, and deployed independently. While this approach offers several benefits, it also introduces new challenges when it comes to communication between micro-frontends.
featured image - Optimal Communication Between Microfrontends and Cross-microfrontend Optimization
Ilyoskhuja HackerNoon profile picture

Micro-frontend architecture is a popular pattern for building large scale web applications. The idea behind it is to split a single application into smaller and independent parts, or micro-frontends, that can be developed, tested, and deployed independently. While this approach offers several benefits, it also introduces new challenges when it comes to communication between micro-frontends.


In this article, we will discuss different options for sharing state and code between micro-frontends and highlight the benefits and drawbacks of each approach. We will also touch upon cross-microfrontend optimization techniques to ensure optimal communication.

Sharing state and code between micro-frontends

  1. Event-driven communication: This approach involves emitting events from one micro-frontend and listening to them in another. The micro-frontends can communicate through a shared event bus or message broker. This approach is simple, but can get complex as the number of micro-frontends grows and the complexity of the system increases.
  2. REST APIs: This approach involves each micro-frontend exposing a REST API and communicating with other micro-frontends through HTTP requests. This approach is more scalable, but requires additional infrastructure and increases the latency of communication.
  3. Shared libraries: This approach involves sharing common libraries between micro-frontends, allowing them to access shared state and code. This approach is highly optimized, but can lead to tight coupling between micro-frontends, making them harder to maintain and scale.
  4. GraphQL: This approach involves using GraphQL to expose a single endpoint for all micro-frontends, allowing them to query and mutate data in a unified manner. This approach is highly optimized, but requires a good understanding of GraphQL and its ecosystem.

Example: Micro-frontend communication in Angular

In Angular, one of the popular frontend frameworks, micro-frontends can communicate through services and state management libraries like @ngrx/store or @ngrx/effects.


For instance, if we want to share a shopping cart state between two micro-frontends, we can create a shared store and expose it through a store service. Each micro-frontend can then subscribe to the store service and update the shared state as needed.

Cross-microfrontend optimization

Optimizing communication between micro-frontends is crucial for ensuring a smooth and seamless user experience. Some of the techniques for optimizing cross-microfrontend communication include:


  1. Caching: Caching the results of API calls or event subscriptions can reduce the latency of communication and improve performance.

  2. Batching: Batching API calls or events can reduce the number of round trips between micro-frontends and improve performance.

  3. Compression: Compressing the data being transmitted between micro-frontends can reduce the amount of data transmitted and improve performance.


In conclusion, there is no one-size-fits-all solution when it comes to micro-frontend communication. The choice of communication approach will depend on the specific use case and requirements. However, by utilizing cross-microfrontend optimization techniques, we can ensure optimal communication between micro-frontends and a smooth user experience.