Over the course of time, micro-frontend architecture has gained popularity in the realm of web design and became one of the most popular front-end development strategies. The framework brings agility and freedom of use which helps diverse set of teams irrespective of the role they play. It imparts ecosystem stability making life easier for CxO’s worldwide.
In a Micro-frontend architecture, the frontend codebase is divided and grouped into autonomous code repositories, each of which acts as an entity which performs separate logically complete business requirements. Together these entities provide a unified experience to the users in the form of a seamless front-end interface which is scalable and maintainable.
It is difficult to maintain everything in a single application when there are more capabilities and functions; the bloated frontend codebase necessitates a lot of work and time.
The initial approach to address this was to partition the backend into microservices that interfaced with a single frontend.
Data from multiple backend services had to be handled by a single frontend in short span of time which led to complicated implementations. In the event we want to upgrade one of the microservices in the backend, it requires changes in frontend too. But designers could disregard such little undertakings and in the long run winding up as re-building is the main coherent arrangement. Individual teams can handle end-to-end development and deployment of their micro apps, thanks to the micro frontend framework.
Figure 1. Micro Frontend user interface
Before creating micro frontends, one should decide s how to divide the frontend application. There can be vertical and horizontal split. The approach is explained considering the development of an application with two pages, Product Details and Product Carousel. It can be built with vertical or horizontal split.
A horizontal split occurs when there are multiple teams, collaborating within a shared interface and must uphold a uniform visual appearance.
Refer to the horizontal split section of Figure 2 below, it is a single view but product details are developed by team A, and product carousel is developed by team B while header & footer is developed by team C. On the vertical split, team a is responsible for all the components in one page while team B is responsible for all the components in another page.
Figure 2. Application Split Types – Vertical vs Horizontal
Horizontal and vertical approaches have different pros and cons. The decision on what approach to go for, should be based on the composition of the different micro front end entities.
Pros and cons of execution approaches
Execution Approach | Pros | Cons |
---|---|---|
Vertical Split | Simpler handling | Challenges with sync across MFEs (Micro frontends) |
Horizontal Split | Better handle on customization | Complexity |
Server-Side Composition
All the micro frontends are invoked and collated in the server before transferring them to the browser. The server then combines the view, invoke micro frontends, and arrange page before it gets rendered. We can always put the core logic in the server to avoid wait time or screen freeze for users. Before the core view loads the rest of the micro, apps will continue to load in the background.
Server-side composition provides a better handle to the output which is great for highly indexed websites such as news or ecommerce. It is also a preferred choice for websites which require superior performance metrics. Horizontal split architectures with a server-side composition provide one of the most powerful and agile solutions available in the micro frontend ecosystem.
Build Time Integration
The build time integration implementation strategy is used to concoct all the micro frontend codebases as individual repositories. All apps are independent, easier to understand and easy to develop & deploy, resulting in faster apps development. The container will install the individual components as libraries and all the packages get compiled at build time and we get everything as a single application.
But the size of the final package will be big in this strategy as it contains all dependencies. Moreover, redeployment is required in case of changes in dependencies. Also, there is a tight coupling between the container and all micro-frontends entities which makes it challenging to independently release separate items.
Building integrations between different components can be challenging, this leads to complicated routing, and deep linking which causes additional challenges to make one’s page responsive. This approach is preferred by several web applications where reliability and execution have more priority over other factors like streaming services.
Run Time Integration
The run time integration is somewhat similar to build time integration but with a small variation where the integrations are done during the run-time using either Java script or web components. This is the most flexible and more frequently used strategy. A script tag is used to add a micro front to the page. The container application then decides which MFE (Micro frontends) component to launch and it invokes the related method to dictate when and where the MFE should execute.
Below are the pros and cons on the integration methods for MFE’s.
Pros and Cons of Integration Options
Integration Method | Pros | Cons |
---|---|---|
Server-side composition |
|
|
Build-time Integration |
|
|
Run-time Integration |
|
|
In conclusion, there's no one-size-fits-all solution when it comes to integrating Micro Frontends. The best approach depends on the requirements and constraints of an eco-system. Server-side composition is suitable for applications with a complex backend, build-time integration is suitable for applications that require high performance, and run-time integration is suitable for applications that require flexibility and dynamic loading.
In the following sections, we will conduct an in-depth analysis of the micro front-end component’s framework. This will involve an explanation of the various components that constitute an application developed using Angular and Bootstrap, as well as their respective roles in optimizing the framework’s functionality within an application.
Application Load Simplistic View
The figure below depicts the view of an application built using Angular and Bootstrap framework leveraging Micro Frontend. Bootstrap framework provides more flexibility in making the portal responsive to different screens and devices.
This would enable developers with scalability and flexibility to add as many pages as required with desired customer navigation experience. Developer can incorporate common styling across portals to support responsive web applications and provide cross-page actions.
Figure 3. Application Simplistic View
Below sections explain each of components in the simplistic view diagram namely Root, Re-usable, Dependencies, Utilities & MFE’s.
Root
Consider root as the main application which loads index.html having script tags and loads the main.js to the browser. main.js fetches the other apps based on the route. The updates need to be communicated across teams.
Dependencies
Dependencies include the common libraries which can be accessed across MFEs.
Code snippet from the root component index.html
Re-Usable
It is the module which is placed in the re-usable entities like tables, maps, filters etc. that are common and generic in functionality and common styles like buttons, colors, forms, fills and text formats. They are used to maintain consistency and standards across the application. Below code snippet defines a custom element to ensure that the components from this can be used in other MFE’s with the ‘CUSTOM_ELEMENT_PREFIX’ as a prefix.
Styles can be imported and used across all the independent MFE’s without defining them again in respective SCSS files.
Utilities
Utilities is one of the MFE which includes the global error handling and managing API (Application Programming Interface) calls like embedding the necessary headers, authentication, relevant error handling, data transformation of the response received and storage services to avoid un-necessary API calls in the same session or within a specified time interval.
MFE’s
MFE’s are the independent development code repositories that can be utilized by multiple teams simultaneously and providing each team with the freedom to select their preferred technology stack for their respective microservices. The heightened level of ownership serves to enhance the quality of decision making, expedite the pace of development sprints, and bolster the range of capabilities that can be autonomously deployed. Developers will have the capacity to utilize reusable components and styles from reusable MFEs, as well as invoke API calls through the services outlined in utilities MFEs.
Above code snippet shows how accessing other MFE’s services or components can be achieved by pushing the required MFE’s into a constant like singleSpaAngularWebpack
Repository Structure
Below is a reference structure for setting up micro front end repositories.
Figure 4. Code Repository Structure
Core
Apps
Every subsequent app must follow the guidelines to ensure and maintain scalability of the architecture.
Deployment View
The deployment of micro front ends can be controlled using reverse proxy where routing of requests to different MFEs is managed by configurations.
Sample template of a reverse proxy config in the web server where the micro frontend applications are deployed.
Below are few learnings from the implementation along with proposed mitigations/recommendations
Micro front ends facilitate teams to concentrate on end-to-end development of respective applications. They can be executed in multiple ways based on business requirements. he most effective and transparent solutions are Horizontal split architectures with a server-side composition. An application developed using micro front ends empowers the developers to utilize the components, styles from re-usable MFE and invoke the API calls using the services defined in utilities. The recommended repository structure includes of a core application referenced across applications in other repositories. The deployment of MFEs can potentially be managed through config files on a web server.
To keep yourself updated on the latest technology and industry trends subscribe to the Infosys Knowledge Institute's publications
Count me in!