Chisom Kanu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # What are micro frontends? ## Introduction The development of [microservices](https://www.ibm.com/topics/microservices#:~:text=Microservices%20%28or%20microservices%20architecture%29%20is%20a%20cloud-native%20architectural,coupled%20and%20independently%20deployable%20smaller%20components%2C%20or%20services.) has been beneficial to large applications in several ways. The backend of the application can be developed, deployed, and scaled with its assistance. Nevertheless, many individuals have observed that the frontend has similar problems. The frontend monolith is now beginning to be divided into smaller frontends. In today’s fast-paced and constantly evolving digital landscape, the need for scalable, flexible, and maintainable frontend applications has never been greater. Micro frontends help address these challenges by allowing teams to work in parallel, reducing the risk of code conflicts, and enabling rapid deployment of new features. Additionally, micro frontends allow organizations to adopt new technologies and practices more easily, improving their ability to respond to changing business requirements and market conditions. In this article, I’ll explain what micro frontends are, how they work, micro frontend architecture, and when to use micro frontends. ## What are Micro Frontends? [Micro frontends](https://www.altexsoft.com/blog/micro-frontend/) are a software [architectural pattern](https://en.wikipedia.org/wiki/Architectural_pattern) that involves breaking down a large, [monolithic frontend ](https://xebia.com/blog/the-monolithic-frontend-in-the-microservices-architecture/)into smaller, independent, self-contained components. Each of these components represents a micro frontend that can be developed, deployed, and maintained independently. By breaking down the monolithic frontend into smaller components, teams can work on individual micro frontends in parallel, reducing the risk of code conflicts and enabling fast deployment of new features. Micro frontends communicate with each other using well-defined [APIs](https://www.guru99.com/what-is-api.html), allowing them to work together seamlessly to deliver a cohesive user experience, it is designed to be reusable, allowing teams to reuse components across multiple projects. ## How does the Micro Frontend Work? In Micro Frontends, each component is deployed as a standalone application, typically hosted on its domain or a subdomain, and communicates with other components through APIs or other communication mechanisms. The components are then composed into a complete application through an orchestrator, which can be a [JavaScript](https://www.javascript.com/) file that coordinates the communication between the components, or a more sophisticated system such as a centralized router, a reverse proxy, or a service worker. Here’s an example of how Micro Frontends can be implemented in a sample application, using [HTML](https://www.w3schools.com/html/) and JavaScript. Consider an e-commerce application, where the frontend is composed of a header, a product list, and a shopping cart. Each of these components can be developed and deployed independently, and then composed into a complete application through an orchestrator. The header component could look like this: ```htmlembedded <header> <h1>E-Commerce App</h1> </header> ``` The product list component could look like this: ```htmlembedded <ul id="product-list"> <li>Product 1</li> <li>Product 2</li> <li>Product 3</li> </ul> ``` And the shopping cart component could look like this: ```htmlembedded <div id="shopping-cart"> <h2>Shopping Cart</h2> <p>No items in cart</p> </div> ``` The orchestrator could then be a JavaScript file that uses dynamic HTML imports to load the components and compose them into a complete application: ```javascript import header from './header.html'; import productList from './product-list.html'; import shoppingCart from './shopping-cart.html'; document.body.appendChild(header); document.body.appendChild(productList); document.body.appendChild(shoppingCart); ``` Each component is deployed as a standalone HTML file, and the orchestrator is a JavaScript file that loads and composes the components into a complete application. This approach allows for each component to be developed and deployed independently, without affecting the other components. The basic concept remains the same: breaking down a monolithic frontend application into smaller, independent components that can be developed and deployed independently, and then composed into a complete application through an orchestrator. ## Why use Micro Frontends Micro frontends enable organizations to adopt a modular approach to frontend development. In a monolithic frontend architecture, all the code for a web application is in one single codebase, which makes it difficult to manage and maintain, however, in a micro frontend architecture, each microservice has its codebase and can be developed, tested, and deployed independently. This allows teams to work on separate parts of the application without affecting the entire codebase, and it makes it easier to scale development efforts as the application grows. In a monolithic frontend architecture, a single bug or error can bring down the entire application, on the other hand, in a micro frontend architecture, each microservice can fail independently without affecting the rest of the application. This improves the reliability of the frontend application and ensures that users can continue to access critical parts of the application even if other parts are down. With micro frontends teams can deploy new features and bug fixes independently, allowing for faster and more frequent releases, This results in a faster time to market for new features and a better user experience. Furthermore, with micro frontends, it is easier to adapt to new technologies independently without affecting the rest of the applications. ## When to Use Micro Frontend Micro frontends are best used if you are working on a large and complex frontend application, it can improve collaboration between teams, as each team can focus on developing a specific part of the application. In addition, it can also make it easier to test, debug, and refactor the code, as each micro frontend can be tested and deployed independently. Companies that use micro frontend are as follows: - [Spotify](https://open.spotify.com/?) - [Upwork](https://www.upwork.com/) - [SouthCloud](https://myaccount.southcloud.online/) - [IKEA](https://www.ikea.com/) - [DAZN](https://www.dazn.com/en-GLOBAL/welcome) Tools and Frameworks for Micro frontends - [Web Components](https://developer.mozilla.org/en-US/docs/web/web_components) - [Single-Spa](https://single-spa.js.org/) - [Podium](https://www.podium.com/1/) - [React](https://reactjs.org/) - [Angular](https://angular.io/) - [Vuejs](https://vuejs.org/) - [Iframe Resizer](http://davidjbradshaw.github.io/iframe-resizer/) ## Implementing Micro Frontends To implement micro frontend architecture, we need to break down the user interface into smaller, independently deployable parts. Each of these parts is called a micro frontend. We'll be looking at how to implement micro frontend architecture using three different approaches - iFrame, Custom Elements, and Web Components. - iFrame One way to implement micro frontend architecture is to use [iFrames](https://www.hostinger.com/tutorials/what-is-iframe/). An iFrame is an HTML element that allows you to embed another HTML document inside your page. This approach involves creating a shell application that embeds multiple micro frontends using iFrames. Each micro frontend is deployed as a standalone application, which can be developed and maintained independently. Here's an example of how to implement micro frontend architecture using iFrames: ```htmlembedded <!DOCTYPE html> <html> <head> <title>Micro Frontend Architecture using iFrames</title> </head> <body> <h1>Micro Frontend Architecture using iFrames</h1> <iframe src="http://microfrontend1.example.com"></iframe> <iframe src="http://microfrontend2.example.com"></iframe> <iframe src="http://microfrontend3.example.com"></iframe> </body> </html> ``` In the above example, we have a shell application that embeds three micro frontends using iFrames. Each micro frontend is deployed as a standalone application with its domain name. When the shell application is loaded, it embeds the micro frontends using iFrames, and the user can interact with each micro frontend independently. - Custom Elements [Custom Elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) is a Web API that allows you to create your HTML elements. With Custom Elements, you can define your tags, attributes, and behaviors, which can be reused across different projects. This approach involves creating custom elements for each micro frontend and then combining them to create the final user interface. Here's an example ```javascript class MicroFrontend1 extends HTMLElement { constructor() { super(); } connectedCallback() { this.innerHTML = ` <h1>Micro Frontend 1</h1> <p>Hello from Micro Frontend 1!</p> `; } } customElements.define('micro-frontend-1', MicroFrontend1); ``` Here, we define a Custom Element called `MicroFrontend1`. The `connectedCallback` method is called when the element is added to the DOM. In this method, we set the HTML content of the element to a simple heading and paragraph. Finally, we define the Custom Element using the `customElements.define` a method, giving it a tag name of `micro-frontend-1`. To combine multiple Custom Elements to create the final user interface, you can use a framework like Angular, React, or Vue. These frameworks provide tools for creating Custom Elements and combining them into a single user interface. - Web Components [Web Components](https://developer.mozilla.org/en-US/docs/web/web_components) is a set of web standards that allow you to create reusable components using HTML, CSS, and JavaScript. With Web Components, you can encapsulate your code, styles, and behavior into a single component that can be reused across different projects. This approach involves creating Web Components for each micro frontend and then combining them to create the final user interface. For Instance: ```javascript class MicroFrontend2 extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); const template = document.createElement('template'); template.innerHTML = ` <style> h1 { color: red; } </style> <h1>Micro Frontend 2</h1> <p>Hello from Micro Frontend 2!</p> `; this.shadowRoot.appendChild(template.content.cloneNode(true)); } } customElements.define('micro-frontend-2', MicroFrontend2); ``` In this example above, we define a Web Component called `MicroFrontend2`. The `constructor` method is called when the element is created. In this method, we attach a shadow DOM to the element, which provides encapsulation for our code and styles. We then create a template element, set its content to our HTML and CSS, and attach it to the shadow DOM. To combine multiple Web Components to create the final user interface, you can use a framework like Stencil or LitElement. These frameworks provide tools for creating Web Components and combining them into a single user interface. ## Best Practices for Implementing Micro Frontends - Define your micro frontend boundaries: The first step in implementing micro frontends is to define the boundaries of each micro frontend. These boundaries should be based on the functionality of the application and the teams responsible for each micro frontend. This will help you to identify the dependencies between the micro frontends and ensure that each team can work independently. - Use a common language: To ensure that all of the micro frontends can communicate with each other, it's essential to use a common language. This language should be agreed upon by all teams involved in the project and should be well-documented. This will help to avoid confusion and ensure that each micro frontend is working as intended. - Use a shared data layer: To enable communication between micro frontends, it's essential to have a shared data layer. This data layer should be accessed by all micro frontends and should contain all of the necessary data for the application. This will help to ensure that each micro frontend has access to the same data and can communicate with each other effectively. - Implement an effective testing strategy: Testing is an essential part of any software development project, and micro frontends are no exception. It's essential to implement an effective testing strategy that includes unit testing, integration testing, and end-to-end testing. This will help to ensure that each micro frontend is functioning correctly and that they are all working together as intended. - Use a consistent UI design system: To ensure a consistent user experience across all micro frontends, it's essential to use a consistent UI design system. This design system should be agreed upon by all teams involved in the project and should include a set of design guidelines and UI components. This will help to ensure that the application looks and feels consistent across all micro frontends. - Monitor and measure performance: To ensure that the application is performing as intended, it's essential to monitor and measure performance. This can be achieved by using monitoring tools and analytics to track performance metrics such as page load times and user engagement. This will help to identify any performance issues and ensure that the application is performing optimally. ## Conclusion Micro frontends offer a new way of building and organizing complex web applications, offering several benefits such as improved development velocity, flexibility, and scalability. It provides a solution to the challenges faced by large web applications. Micro frontends work by dividing a large web application into smaller, self-contained components that can be composed together to form the complete application. The composition of the micro frontends can be done in several ways, including [server-side composition](https://www.tpeczek.com/2022/07/micro-frontends-in-action-with-aspnet.html#:~:text=Server-side%20composition%20is%20a%20technique%2C%20where%20the%20page,fragments%20it%20requires%20to%20build%20its%20own%20UI.), [client-side composition](https://www.tutorialspoint.com/microservices_design_patterns/microservices_design_patterns_client_side_ui_composition.htm), and [hybrid composition](https://github.com/flutter/flutter/wiki/Hybrid-Composition/9fccae55abdb8f241b1f9c07b876864179401425). If you are considering a frontend architecture for your organization, the micro frontend should be on your list of options.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully