avatarCaleb

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3787

Abstract

 <span class="hljs-tag">&lt;<span class="hljs-name">FooterApp</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>

); }</pre></div><p id="06e8">This looks pretty similar to the previous code, doesn’t it? That’s the beauty of it! You still maintain a unified look and feel, but now each component is an independent micro-app.</p><h1 id="f1bd">Guiding the Ship: Implementing Micro-Frontends</h1><p id="29e1">Adopting a micro-frontend architecture doesn’t mean you need to toss out your existing codebase. A gradual adoption is very much possible, and encouraged!</p><p id="0bc5">You can start by identifying logical parts of your application that can work as separate entities. For instance, in an e-commerce site, product listings, user account details, and shopping cart could be separate micro-frontends.</p><p id="6813">In a junior developer’s journey, it’s essential to get a hands-on feel of what we’re learning. So, let’s build a micro-frontend using a tool named <code>Single-spa</code>. It's a routing framework for building micro-frontends, and it works with any JavaScript framework.</p><p id="884e">Let’s define an application shell, the core of our application.</p><div id="0828"><pre><span class="hljs-keyword">import</span> { registerApplication, start } from <span class="hljs-string">'single-spa'</span>;

registerApplication( <span class="hljs-string">'navBar'</span>, () => <span class="hljs-keyword">import</span>(<span class="hljs-string">'./src/navBar/navBar.app.js'</span>), () => <span class="hljs-keyword">true</span> );

registerApplication( <span class="hljs-string">'home'</span>, () => <span class="hljs-keyword">import</span>(<span class="hljs-string">'./src/home/home.app.js'</span>), () => location.pathname === <span class="hljs-string">"/"</span> );

registerApplication( <span class="hljs-string">'user'</span>, () => <span class="hljs-keyword">import</span>(<span class="hljs-string">'./src/user/user.app.js'</span>), () => location.pathname.startsWith(<span class="hljs-string">'/user'</span>) );

start();</pre></div><p id="7e55">Here, each <code>registerApplication</code> call takes in the name of the micro-frontend, its source file, and when to show it based on the route. We then call <code>start()</code> to start our application.</p><h1 id="add0">A New Horizon: Benefits of Micro-Frontends</h1><p id="7b7f">While the initial setup may seem a bit daunting, the benefits of adopting a micro-frontend architecture can be monumental. It allows for independent deployment, reduces the risk of failure, and increases development speed by allowing parallel development in separate codebases. Most importantly, it creates a more manageable and scalable system, one that is not only beneficial for the organization but also makes developers’ lives easier.</p><h1 id="87ba">In Conclusion: Small is the New Big</h1><p id="3773">Breaking down a monolithic frontend into micro-frontends is like building a fleet of ships instead of one gigantic Titanic. Each can navigate the waters independently, making the journey more efficient and flexible.</p><p id="1010">For junior developers, understanding micro-frontends provides a unique opportunity to grasp the concepts of scalability and reliability in web development. Remember, every large application starts small. So, don’t hesitate to dive in and get your hands dirty with the code. The experience will be invaluable.</p><p id="6f94">Micro-frontends are not a silver bullet, and they might not be the best fit for every scenario. But, if your web application is becoming difficult to manage, or if you’re planning to develop a large-scale application from scratch, adopting a micro-frontend architecture could

Options

steer your application towards smooth sailing waters.</p><p id="a75d">Remember, it’s not about creating a gigantic ship that might sink, it’s about creating a resilient and flexible fleet that will continue to sail no matter what. And with that, we conclude our journey through the exciting waters of micro-frontends. Safe sailing!</p><ol><li><a href="https://martinfowler.com/articles/micro-frontends.html"><b><i>Micro Frontends — Martin Fowler</i></b></a><b><i>:</i></b><i> This is a comprehensive guide by Martin Fowler, a renowned thought leader in the world of software development. This resource provides a detailed introduction to micro-frontends.</i></li><li><a href="https://www.manning.com/books/micro-frontends-in-action"><b><i>Micro Frontends in Action — Michael Geers</i></b></a><b><i>:</i></b><i> This book provides a hands-on approach to implementing micro-frontends. It includes real-world examples and in-depth explanations of micro-frontend architecture.</i></li><li><a href="https://single-spa.js.org/"><b><i>Single-spa.js Documentation</i></b></a><b><i>:</i></b><i> This is the official documentation of the Single-spa framework, which is very helpful for implementing micro-frontends.</i></li></ol><div id="c855" class="link-block"> <a href="https://medium.com/@calebpr/subscribe"> <div> <div> <h2>Get an email whenever Caleb publishes.</h2> <div><h3>Get an email whenever Caleb publishes. By signing up, you will create a Medium account if you don’t already have one…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*pPSGj3ORvqLvuBYg)"></div> </div> </div> </a> </div><p id="91bd"><i>Enjoyed the read? For more on Web Development, JavaScript, Next.js, Cybersecurity, and Blockchain, check out my other articles here:</i></p><div id="7e3a" class="link-block"> <a href="https://readmedium.com/a-roadmap-to-my-medium-writings-fd04e14cffd7"> <div> <div> <h2>A Roadmap to My Medium Writings</h2> <div><h3>undefined</h3></div> <div><p>undefined</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*FO4S90VIpPA05s9cP-gFPQ.png)"></div> </div> </div> </a> </div><p id="8496"><i>If you have questions or feedback, don’t hesitate to reach out at [email protected] or in the comments section.</i></p><p id="c73a"><i>[Disclosure: Every article I pen is a fusion of my ideas and the supportive capabilities of artificial intelligence. While AI assists in refining and elaborating, the core thoughts and concepts stem from my perspective and knowledge. <a href="https://readmedium.com/how-does-ai-help-me-write-my-articles-5df265d16527">To know more about my creative process, read this article.</a>]</i></p><div id="a005" class="link-block"> <a href="https://readmedium.com/how-does-ai-help-me-write-my-articles-5df265d16527"> <div> <div> <h2>How Does AI Help Me Write My Articles?</h2> <div><h3>The Medium landscape has seen a transformation, with an increasing number of articles appearing to have the distinct…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*sURudlO3SS5ntthELFumcg.jpeg)"></div> </div> </div> </a> </div></article></body>

Micro-frontends: Breaking Down Monolithic Frontend Architecture for Scalable Web Applications

When we talk about the titanic, what comes to mind first? Well, of course, the tragic sinking. But, on the brighter side, it also represents a colossal, intricately designed structure that carried numerous separate entities.

Think of a monolithic frontend application as the Titanic, only floating and quite functional. Each part of the ship has its purpose, but in its entirety, the ship is a single unit. Similarly, in a monolithic application, each component has a role, but they are all part of a single codebase.

However, just as the Titanic would have fared better divided into smaller, independent compartments, your web application can also gain a lot from being broken down into micro-frontends.

Let’s dive deeper!

Unsplash

The Iceberg of Monolithic Frontend Architecture

Traditionally, many companies opt for a monolithic frontend architecture. A single team would handle everything — from user interface components to business logic. But as the application grows, maintaining this colossal structure becomes as difficult as steering a giant ship.

Imagine changing a piece of code that might affect unrelated parts of your application. Or even worse, what about dealing with the merge conflicts when multiple developers are trying to push their changes at once?

Now, let’s look at a piece of code as an example.

function MyBigApp() {
  return (
    <div>
      <Header />
      <Main />
      <Footer />
    </div>
  );
}

In the above code, Header, Main, and Footer are all different components of a single-page application. They all reside in the same codebase and are tightly coupled. This means if Header fails, there's a risk the whole application will go down. This is a monolithic frontend architecture.

Lifeboats of Micro-Frontends

Micro-frontends come to the rescue here. Imagine breaking down your MyBigApp into smaller independent apps: HeaderApp, MainApp, and FooterApp. Each of these apps can be developed, tested, deployed, and scaled independently. If HeaderApp fails, it won't bring down the whole application, much like how the sinking of one compartment wouldn't sink the entire ship.

Let’s see how the code changes with a micro-frontend architecture.

function MyDecoupledApp() {
  return (
    <div>
      <HeaderApp />
      <MainApp />
      <FooterApp />
    </div>
  );
}

This looks pretty similar to the previous code, doesn’t it? That’s the beauty of it! You still maintain a unified look and feel, but now each component is an independent micro-app.

Guiding the Ship: Implementing Micro-Frontends

Adopting a micro-frontend architecture doesn’t mean you need to toss out your existing codebase. A gradual adoption is very much possible, and encouraged!

You can start by identifying logical parts of your application that can work as separate entities. For instance, in an e-commerce site, product listings, user account details, and shopping cart could be separate micro-frontends.

In a junior developer’s journey, it’s essential to get a hands-on feel of what we’re learning. So, let’s build a micro-frontend using a tool named Single-spa. It's a routing framework for building micro-frontends, and it works with any JavaScript framework.

Let’s define an application shell, the core of our application.

import { registerApplication, start } from 'single-spa';

registerApplication(
  'navBar',
  () => import('./src/navBar/navBar.app.js'),
  () => true
);

registerApplication(
  'home',
  () => import('./src/home/home.app.js'),
  () => location.pathname === "/" 
);

registerApplication(
  'user',
  () => import('./src/user/user.app.js'),
  () => location.pathname.startsWith('/user')
);

start();

Here, each registerApplication call takes in the name of the micro-frontend, its source file, and when to show it based on the route. We then call start() to start our application.

A New Horizon: Benefits of Micro-Frontends

While the initial setup may seem a bit daunting, the benefits of adopting a micro-frontend architecture can be monumental. It allows for independent deployment, reduces the risk of failure, and increases development speed by allowing parallel development in separate codebases. Most importantly, it creates a more manageable and scalable system, one that is not only beneficial for the organization but also makes developers’ lives easier.

In Conclusion: Small is the New Big

Breaking down a monolithic frontend into micro-frontends is like building a fleet of ships instead of one gigantic Titanic. Each can navigate the waters independently, making the journey more efficient and flexible.

For junior developers, understanding micro-frontends provides a unique opportunity to grasp the concepts of scalability and reliability in web development. Remember, every large application starts small. So, don’t hesitate to dive in and get your hands dirty with the code. The experience will be invaluable.

Micro-frontends are not a silver bullet, and they might not be the best fit for every scenario. But, if your web application is becoming difficult to manage, or if you’re planning to develop a large-scale application from scratch, adopting a micro-frontend architecture could steer your application towards smooth sailing waters.

Remember, it’s not about creating a gigantic ship that might sink, it’s about creating a resilient and flexible fleet that will continue to sail no matter what. And with that, we conclude our journey through the exciting waters of micro-frontends. Safe sailing!

  1. Micro Frontends — Martin Fowler: This is a comprehensive guide by Martin Fowler, a renowned thought leader in the world of software development. This resource provides a detailed introduction to micro-frontends.
  2. Micro Frontends in Action — Michael Geers: This book provides a hands-on approach to implementing micro-frontends. It includes real-world examples and in-depth explanations of micro-frontend architecture.
  3. Single-spa.js Documentation: This is the official documentation of the Single-spa framework, which is very helpful for implementing micro-frontends.

Enjoyed the read? For more on Web Development, JavaScript, Next.js, Cybersecurity, and Blockchain, check out my other articles here:

If you have questions or feedback, don’t hesitate to reach out at [email protected] or in the comments section.

[Disclosure: Every article I pen is a fusion of my ideas and the supportive capabilities of artificial intelligence. While AI assists in refining and elaborating, the core thoughts and concepts stem from my perspective and knowledge. To know more about my creative process, read this article.]

Programming
Micro Front End
Technology
Software Development
Web Development
Recommended from ReadMedium