“Microfrontends” for Mobile in React Native

Rate this content
Bookmark

Scaling has always been an issue in software development. Architects have been grappling to solve this problem on many layers. In the early 2000s, a concept of “micro-services” started popping up - a system could be split up by business domain into a number of smaller loosely-coupled services. 


More recently, this concept has started being adopted by the frontend community. An app could be split into multiple sub-apps, each with their own teams, technologies, and codebases. Companies like Spotify, Amazon, and Microsoft have adopted this approach and it has helped them scale even faster.


In the world of mobile development, the question arises: “Can we create Microfrontends for mobile apps?”.

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

Watch video on a separate page

FAQ

Mo discusses using over-the-air updates via CodePush for deploying updates to the JavaScript layer of React Native applications, allowing for faster iterations and quicker bug fixes without needing to go through app store approvals for every update.

Mo highlights several challenges with micro frontends in mobile applications, including the complexities of managing multiple JavaScript bundles, the inability to code push native code, and the need for coordinated management of native dependencies across different teams.

In the streaming service project, a modular feature-driven design was used, allowing different development teams to work autonomously on separate packages of the application, such as live streams, news articles, and podcasts, enhancing development efficiency and reducing conflicts.

Theodo, the company where Mo is the head of mobile, has contributed to the React Native community by adopting React Native early on, releasing various open-source projects like the React Native Image Resizer Library and Flashlight, a performance measurement tool for mobile apps.

Mo's talk at React Advanced is focused on exploring micro frontends for mobile using React Native, discussing its feasibility, potential benefits, and challenges in implementing this architectural style in mobile applications.

Mo is optimistic about future developments where Metro, the primary bundler for React Native, could potentially support module federation, enabling more effective and efficient implementation of micro frontends in mobile applications.

Micro frontends are an architectural style where independent, deliverable frontend applications compose a greater application. For React Native, this involves potentially using separate JavaScript bundles for different features of a mobile app, which can be independently developed and updated.

Mo Khazali
Mo Khazali
24 min
23 Oct, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Micro frontends are an architectural style where independent deliverable frontend applications compose a greater application. They allow for independent development and deployment, breaking down teams into feature verticals. React Native's architecture enables updating the JavaScript layer without going through the app store. Code Push can be used to deploy separate JavaScript bundles for each micro frontend. However, there are challenges with managing native code and dependencies in a micro frontend ecosystem for mobile apps.

1. Introduction to Micro Frontends with React Native

Short description:

I'm super excited to be doing this talk on micro frontends for mobile with React Native. A little bit about me. My name is Mo. I am the head of mobile at a company called Theodo based in the UK. We have been doing React Native for a very long time. In the last few months, we were approached by a client to develop a streaming service. With universal apps, the idea is that you write once and you can run anywhere. You try to reuse as much of your core component logic and your business logic across the board. How do we architect a project at this scale? How do we create the right work stream so that our teams can simultaneously develop? One of the things that we did was we tried to take the main features of the application and put them inside of packages that teams could develop autonomously.

Hey everyone, nice to be with you all at React Advanced this year. I'm super excited to be doing this talk on micro frontends for mobile with React Native. It's a topic that I've been exploring a little bit for the past few months and I think there's a lot of interesting learnings and I hope that by the end of it I will have piqued your interest to explore a little bit more in an area that I think is a little bit underdeveloped and there's a lot of scope for improvement within our community. So yeah, hopefully some exciting stuff will come out of this.

A little bit about me. My name is Mo. I am the head of mobile at a company called Theodo based in the UK. Theodo is a group of international consultants, digital experts that are located around the world, mainly based in France, the UK, New York and also in Morocco. We have been doing React Native for a very long time. You may know us by another name, BAM, where we've been working on open-source in React Native since the very beginning. We adopted React Native back when it came out a few months after it was released by Meta, and we've released various open-source projects like the React Native Image Resizer Library, and more recently Flashlight, which is a tool to measure performance for mobile apps.

Being in the consultancy space, you get to experience a lot of different projects, and I want to talk to you a little bit about one of them today. Story time. In the last few months, we were approached by a client to develop a streaming service. Now, this is a full-scale media platform. It's not just streaming with some videos and just a very basic site. It was the full-fledged thing, with news, with streaming, reading articles, listening to podcasts, all centralized into this one platform that had quite a lot of different moving features about it. The key points in this project was that, one, there was a large number of features, but they had a bunch of other requirements that made it more complex. One was that they wanted it to have feature parody across web, mobile, and even TV. They wanted to have very short turnaround, which meant that we needed to have several teams of developers working on this project simultaneously.

So, being a bit familiar with the React Native space, one of the things that we went for when we heard about parody across the board was this idea of universal apps. This is a space that is developing and I think coming to fruition in the past few years. With universal apps, the idea is that you write once and you can run anywhere. You can use React Native really to create a web application, a mobile application, a desktop application, and even maybe a TV application. You try to reuse as much of your core component logic and your business logic across the board and super powerful in the sense that you can have many, many gains in terms of speed and delivery and rate of iteration and innovation. So it's a very exciting space to be in and we knew that this was going to be a good fit because our project was going to be mobile first but they also needed access to web and TV, so it was kind of a no brainer for us. But it also got us thinking about something a little bit more subtle, which was how do we architect a project at this scale? How do we create the right work stream so that our teams can simultaneously develop? We've got tens of different developers working on this project at the same time. How do you organize it in a way where people aren't stepping on each others' toes? People aren't having too many different sort of merge conflicts or too many different blockers along the way of their development. So one of the things that we looked at very heavily was how do we structure this project? Now this is a simplified folder structure, but hopefully it gets the point across. One of the things that we did was we tried to take the main features of the application and put them inside of packages that teams could develop autonomously.

2. Introduction to Micro Frontends

Short description:

Some of the main features were isolated into separate packages that could be used inside the application. This modular feature-driven design works well for universal and React Native applications. The next natural step is to explore microfrontends for mobile. Microfrontends are not suitable for every project, but they can be beneficial for large-scale projects with autonomous teams. The story of micro frontends begins with the transition from monoliths to microservices in the backend. As applications grow, maintaining a monolithic frontend becomes challenging, slowing down development speed.

So some of the main features were things like watching live streams or reading news articles or maybe listening to a podcast. And so we isolated these features into separate packages that could then be used inside of the application. And these were eventually building blocks that would come together and build the full fledged platform.

And one of the nice things about packaging like this was that we could effectively take any of these modules, isolate them, test them individually, they could be developed in isolation without needing to deal with all of the other stuff that the teams were working with, which meant that the developers wouldn't really get blocked at any point. And this sort of modular feature driven design really works quite well for universal applications and React Native applications.

Because when we started to break down our teams, we saw that we had created these nice feature verticals where a single team was focusing on business logic on the front end, they were creating common React Native components. But they were also coding in Native for iOS and Android and web and really understanding the core of the feature that they were building and becoming specialists in that. We really like that, but it wasn't a new concept. The next natural step that you could take from this was to go down the microfrontend's route.

So it kind of piqued this question in my mind around whether or not microfrontend for mobile is something that is feasible. And so that's what we're gonna explore together today. This is very much an exploratory talk. We're not looking to... I'm not here to advocate going full fledged with microfrontends and adopting them for every single project that you use because that is nonsense. I think there's a lot that we can learn from this approach. It's applicable to a very specific type of project. It can help a lot of projects that are at scale and they're very, very large and with a large number of teams that can be autonomous, but it's not for every single project. So I want to put that grain of salt there just so that everyone is aware this isn't advocating that you should use this on every single project that you go on from now on.

So let's go through a little bit of a history lesson. From monoliths to microservices. So ironically, the story of front ends, the story of micro front ends, starts from the backend where applications started to go from monoliths to microservices. So let's say you've got a basic backend that handles three main features, authentication, streaming and payments. So they're stored under one umbrella application. So all of them fit into one app that is a monolith and so that's fine. That's really three features. There isn't much surface area, but naturally over time you start to add more and more features. And so the app grows. And suddenly as this project is growing larger and larger, you're inevitably stuck with sort of a behemoth of an application. And every single new developer that comes on has this cognitive load that is just massive to deal with. And so the speed of the team will naturally start to slow down and down as you start to build more and more into this application.