We Accidentally Built a Plugin SDK for Micro Frontends

Rate this content
Bookmark

React portals + RxJs = micro frontends on steroids.

At bettermarks, we are migrating an AngularJS app to React using micro frontends. Picture a dashboard with widgets from different frontends depending on permissions and settings without coupling.

We implemented a reliable solution for our micro frontends - and yes, we can embed React components within AngularJs!

I'll showcase our solution and demonstrate how this can help you build more robust applications by trying to break our.

This talk has been presented at React Advanced 2024, check out the latest edition of this React Conference.

FAQ

Betamax initially used a traditional multi-page application powered by PHP.

Betamax aims for no or close to no coupling between applications, adaptability based on roles and permissions, and separation of concerns on the micro frontend level.

Betamax decided to migrate from AngularJS to React after Google discontinued long-term support for AngularJS.

No, Betamax uses a single shared version of React for all micro frontends.

Andre is a principal engineer at Betamax, a Berlin-based education tech company.

Betamax used a micro frontend approach to iteratively migrate from AngularJS to React.

Betamax currently runs 58 microfrontends.

Betamax employs a testing pyramid strategy, using React testing library for low-level testing, snapshot testing, integration tests for interactions, and end-to-end testing for smoke tests.

The talk focuses on how Betamax accidentally built a plugin SDK for microfrontends while migrating from AngularJS to React.

Cross-application communication is handled via services using RxJS under the hood, allowing for communication without direct coupling between apps.

André Bauer
André Bauer
27 min
25 Oct, 2024

Comments

Sign in or register to post your comment.
  • André Bauer
    André Bauer
    bettermarks
    In case you tried to get to the gist - the QR code is faulty. Here is the link: https://gist.github.com/AnBauer/52b85aa1efa52d842d0ce1ac26e2e61d
  • André Bauer
    André Bauer
    In case you tried to get to the gist - the QR code is faulty. Here is the link: https://gist.github.com/AnBauer/52b85aa1efa52d842d0ce1ac26e2e61d
Video Summary and Transcription
Welcome to the talk on Microfrontends and Betamax. The speaker shares their experience of accidentally building a plugin SDK for microfrontends. They discuss the goals and bootstrapping process, emphasizing the importance of adaptability and separation of concerns. The use of behavior subjects and portal rendering is explained, along with the composition and resilience of microfrontends. The speaker demonstrates rendering REC.js within AngularJS and highlights the challenges of handling communication and deployment. They also discuss managing breaking changes, local development, testing, and shared dependencies. The talk concludes with a humorous anecdote and contact information for further engagement.

1. Introduction to Microfrontends and Betamax

Short description:

Welcome everyone to the, as mentioned, last talk of at least this track. I will be sharing how we accidentally built a plugin SDK for microfrontends, referred to as microfrontends on steroids. Quick intro about me, my name is Andre, a principal engineer at Betamax. In 2008, we built a traditional multi-page application powered by PHP. Later, we decided to build a single-page application using AngularJS. After nine years, we had to migrate from AngularJS to React using a micro frontend approach. We now run a full-blown micro frontend setup with 58 micro frontends and counting.

Welcome everyone to the, as mentioned, last talk of at least this track. I'm first and foremost super excited to be here. One of the reasons is that this is actually the first time I'm talking at a conference, and the other reason is that I will be sharing how we accidentally built a plugin SDK for microfrontends, which I refer to as microfrontends on steroids, but the responsibility in me put in the disclaimer, so really bad.

Quick intro for me or about me, it's, my name is Andre, I'm a principal engineer at Betamax, which is a Berlin based education tech company and happens to build, have built the world's most advanced adaptive learning and teaching systems for school. So besides, as mentioned, building digital products, I love to build actual things also, so in case you get already tired about talking about code, then hit me up and we can talk about woodworking or water sports for that matter, but back to the topic, how did we get there?

In order to answer the question, I want to give you a little context of the problem we are trying to solve and how we ended up in the position of having to solve it in the first place. So I'm old, which is not the root cause of the problem of course, but it means that back in 2008 when Betamax started development, I was amongst the first developers who, who kicked us off and we built a traditional multi-page application powered by PHP, which got us quite far.

In fact, so far that four and a half years later, we were able to announce that Uruguay has chosen Betamax to provide all math material for all the schools, which was a huge win back in the days, but it also meant that we will have a problem pretty soon because from the data we got in Germany, we know this setup would not scale on the level of a whole country. So, we thought it would be a nice idea to build a single page application, hot shit back in the day. By chance, any one of you know, when React was open sourced? One month later. So I think it's time to address the elephant in the room. We are at the React conference, but at this point in time, we went with the only reasonable choice being AngularJS.

So we, we in fact built the app, we shipped it and we built upon this base ever since actually. So, but fast forward, nine years later, the inevitable happened and Google discontinued the long-term support for AngularJS. I mean, quite some time to be fair. Um, at this time I was, I already rejoined Betamax, uh, with a mission to come up with a plan of how to iteratively migrate from AngularJS to React. So I rooted for a micro frontend approach and we executed it with a single span, which is basically a JavaScript router for micro services in the frontend. And it differentiates amongst other things, different types of micro frontends, which I will quickly explain because I will use the terminology moving forward.

So we have apps, of course, which are just like any other single page app, but without an actual HTML page. We have a root config which provides this root HTML page, it handles app registration, mounting, unmounting. So it is responsible for the whole composition of the micro frontend setup. Then we have utilities to share common logic and like services or component lib and we have parsers to share UI between frameworks. This will be important later. Um, our proof of concept was fairly easy done. So we implemented the navigation and react and kept the content area as a stripped down AngularJS version with bespoke bootstrapping process for the app, which worked pretty nicely.

So we put a whole team on it and started developing fast forward to this point. We now run a full blown micro frontend setup where apps can render parts within other apps where we are currently at 58 micro frontends and still counting. We have services, utility micro frontends that provide shared APIs, including global state management and behind the scenes, we do this with RxJS quite heavily. And yes, we still have some use cases in AngularJS, unfortunately, but we are getting there. Um, yeah, I did promise you that. I know.

2. Goals and Bootstrapping Process

Short description:

We aim for no or close to no coupling between applications. The root config controls the app composition. We want to be adaptable based on roles, permissions, licenses, feature toggles, and settings. Our goal is to achieve separation of concerns, encapsulation, and bounded context on the micro frontend level. In a live demo, I'll show you Better Marks from a student perspective. We have a hated view, the homework section, and a digital replacement for student school books called Teaching a School Book. We use a feature toggle to activate content. The bootstrapping process involves registering apps, such as the assignments app and the learning units app. The portal service handles rendering content into the correct DOM node.

Um, but first what are we trying to achieve actually from a goals perspective? So, um, we want to have no or close to no coupling between applications. The root config is the one and only place that controls the composition of apps. We want to be adaptable. That means, um, the composition of these apps is based on roles, permissions, licenses, feature toggles and settings so that different users can put, could potentially have different user experiences. And from an architectural standpoint, we want to, we aim for separation of concerns, encapsulation and bounded context on micro frontend level.

Yeah. So without further ado, I thought it would be a good idea for your very first talk to go with a live demo because why not? Um, so this is better marks from a student perspectives. We are looking at one of the most hated views from a student for students because when stuff shows up there, it means homework, usually. And the content there is just one of the most hated views for students. And the content there is from our practicing product. We also have a different one that is called teaching a school book, which is a digital replacement for physical student school books.

Um, the red line at the top marks an extension point that we call portal slots. Nothing shows up here. And I will show you why, because the feature toggle is not active. So if I, if I activate this feature toggle and reload. So now content shows up. Yeah, fair enough. So this is stuff that teachers distributed to the students to look at. And in order to understand our approach, I will walk you through the bootstrapping process of this page. Now you already saw the feature toggle. So root configuration takes care of registering apps, as I mentioned. So it has, uh, it knows about the user. Therefore it knows about potential licenses and if the license match or is sufficient, we also register the assignments app, what we just saw, the homework stuff. Then for activated feature toggle school book, we also, um, register the learning register, the learning units app that provides the distributed, um, content from the school book product, whether or not an registered app is active, is determined by signals bar for it by executing the is active function for every registered application. And this case, um, the route for the assignments and the allocated learning units match. So both are, both are mounted at this view. If now one view wants to offer one of these port slots, they just have to use our portal store with the desired slot, which will get them a callback ref. A component that wants to render into one of those extension points, a.k.a. portal slots, use our portal renderer to get a custom create portal function that will take care of rendering your content into the correct DOM node once it's mounted. And the really interesting part happens in our portal service.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
Understanding React’s Fiber Architecture
React Advanced 2022React Advanced 2022
29 min
Understanding React’s Fiber Architecture
Top Content
This Talk explores React's internal jargon, specifically fiber, which is an internal unit of work for rendering and committing. Fibers facilitate efficient updates to elements and play a crucial role in the reconciliation process. The work loop, complete work, and commit phase are essential steps in the rendering process. Understanding React's internals can help with optimizing code and pull request reviews. React 18 introduces the work loop sync and async functions for concurrent features and prioritization. Fiber brings benefits like async rendering and the ability to discard work-in-progress trees, improving user experience.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
Monolith to Micro-Frontends
React Advanced 2022React Advanced 2022
22 min
Monolith to Micro-Frontends
Top Content
Microfrontends are considered as a solution to the problems of exponential growth, code duplication, and unclear ownership in older applications. Transitioning from a monolith to microfrontends involves decoupling the system and exploring options like a modular monolith. Microfrontends enable independent deployments and runtime composition, but there is a discussion about the alternative of keeping an integrated application composed at runtime. Choosing a composition model and a router are crucial decisions in the technical plan. The Strangler pattern and the reverse Strangler pattern are used to gradually replace parts of the monolith with the new application.
The Eternal Sunshine of the Zero Build Pipeline
React Finland 2021React Finland 2021
36 min
The Eternal Sunshine of the Zero Build Pipeline
For many years, we have migrated all our devtools to Node.js for the sake of simplicity: a common language (JS/TS), a large ecosystem (NPM), and a powerful engine. In the meantime, we moved a lot of computation tasks to the client-side thanks to PWA and JavaScript Hegemony.
So we made Webapps for years, developing with awesome reactive frameworks and bundling a lot of dependencies. We progressively moved from our simplicity to complex apps toolchains. We've become the new Java-like ecosystem. It sucks.
It's 2021, we've got a lot of new technologies to sustain our Users eXperience. It's time to have a break and rethink our tools rather than going faster and faster in the same direction. It's time to redesign the Developer eXperience. It's time for a bundle-free dev environment. It's time to embrace a new frontend building philosophy, still with our lovely JavaScript.
Introducing Snowpack, Vite, Astro, and other Bare Modules tools concepts!
Composition vs Configuration: How to Build Flexible, Resilient and Future-proof Components
React Summit 2022React Summit 2022
17 min
Composition vs Configuration: How to Build Flexible, Resilient and Future-proof Components
Top Content
Today's Talk discusses building flexible, resilient, and future-proof React components using composition and configuration approaches. The composition approach allows for flexibility without excessive conditional logic by using multiple components and passing props. The context API can be used for variant styling, allowing for appropriate styling and class specification. Adding variants and icons is made easy by consuming the variant context. The composition and configuration approaches can be combined for the best of both worlds.

Workshops on related topic

AI on Demand: Serverless AI
DevOps.js Conf 2024DevOps.js Conf 2024
163 min
AI on Demand: Serverless AI
Top Content
Featured WorkshopFree
Nathan Disidore
Nathan Disidore
In this workshop, we discuss the merits of serverless architecture and how it can be applied to the AI space. We'll explore options around building serverless RAG applications for a more lambda-esque approach to AI. Next, we'll get hands on and build a sample CRUD app that allows you to store information and query it using an LLM with Workers AI, Vectorize, D1, and Cloudflare Workers.
Micro Frontends with Module Federation and React
JSNation Live 2021JSNation Live 2021
113 min
Micro Frontends with Module Federation and React
Top Content
Workshop
Alex Lobera
Alex Lobera
Did you ever work in a monolithic Next.js app? I did and scaling a large React app so that many teams can work simultaneously is not easy. With micro frontends you can break up a frontend monolith into smaller pieces so that each team can build and deploy independently. In this workshop you'll learn how to build large React apps that scale using micro frontends.
High-performance Next.js
React Summit 2022React Summit 2022
50 min
High-performance Next.js
Workshop
Michele Riva
Michele Riva
Next.js is a compelling framework that makes many tasks effortless by providing many out-of-the-box solutions. But as soon as our app needs to scale, it is essential to maintain high performance without compromising maintenance and server costs. In this workshop, we will see how to analyze Next.js performances, resources usage, how to scale it, and how to make the right decisions while writing the application architecture.
Micro-Frontends with Module Federation and Angular
JSNation Live 2021JSNation Live 2021
113 min
Micro-Frontends with Module Federation and Angular
Workshop
Manfred Steyer
Manfred Steyer
Ever more companies are choosing Micro-Frontends. However, they are anything but easy to implement. Fortunately, Module Federation introduced with webpack 5 has initiated a crucial change of direction.
In this interactive workshop, you will learn from Manfred Steyer -- Angular GDE and Trusted Collaborator in the Angular team -- how to plan and implement Micro-Frontend architectures with Angular and the brand new webpack Module Federation. We talk about sharing libraries and advanced concepts like dealing with version mismatches, dynamic Module Federation, and integration into monorepos.
After the individual exercises, you will have a case study you can use as a template for your projects. This workshop helps you evaluate the individual options for your projects.
Prerequisites:You should have some experience with Angular.