Server-Driven Mobile Apps With React Native
From Author:
How do you create a scalable application with lots of different layouts, screens, giving enough flexibility to each team to customise without adding orders of magnitude in complexity to your app? Companies like Airbnb, Meta, and Lyft approach this with server-driven UI. We’ll explore how this can work for mobile apps, challenges that it introduces, and how it’s the way forward in the age of React Server Components.
This talk has been presented at React Summit 2024, check out the latest edition of this React Conference.
FAQ
In an e-commerce platform like React Cloth, server-driven UI defines the layout using a JSON blob from an API or CMS. This JSON includes various sections like offers, recommended products, and testimonials, which are then dynamically rendered by the client-side code.
Project Lightspeed was an initiative by Facebook to reduce the complexity and size of the Messenger app. By adopting server-driven UI, they were able to cut down from 1.7 million lines of code to 360,000 and reduce the bundle size from 130 megabytes to 30 megabytes.
You can learn more about server-driven UI in React Native by watching talks and presentations from experts. A highly recommended talk is by Evan Bacon from the Expo team, discussing React Server Components within the Expo Router.
Some challenges associated with server-driven UI include handling caching and offline support, managing the complexity of dynamic layouts, and ensuring seamless integration between server-side and client-side components.
Airbnb adopted server-driven UI to achieve platform consistency across web, iOS, and Android. It helped them unify components across different parts of their platform and add new features without significant rework.
Server-driven UI helps in creating scalable and complex UIs in React Native applications by reducing code duplication and simplifying layout definitions. It allows for dynamic UI updates without requiring significant changes to the client-side code.
The advantages of using server-driven UI include reduced code duplication, simplified layout management, dynamic UI updates, and improved performance. It also allows for more flexible and scalable UI designs.
Server-driven UI helped Facebook Messenger reduce code duplication and simplify layout management. This led to a significant reduction in codebase size and bundle size, improving app performance and maintainability.
Server-driven UI is a design pattern where the server controls the UI layout by sending a JSON blob that defines the layout of the page. This allows for more scalable and complex UIs without significant code duplication.
Companies like Shopify, Airbnb, and Lyft are using server-driven UI. Shopify uses it for their shop app, Airbnb for platform consistency across web and mobile, and Lyft for dynamically controlling layouts for different user requirements.
Video Transcription
1. Introduction to Server-driven UI
Today, we are going to be taking a look at server-driven UI and how you can use it within your React Native applications to create more scalable and complex UIs and layouts without incurring a lot of cost and tech debt. The best way to talk about server-driven UI is to go through a very concrete story from the industry. Let's go back in our timelines, back from 2024 all the way to 2019. For the folks at Facebook before they were called meta, they were just releasing out a lot of new features into the messenger app. This app was expanding very quickly, resulting in slow app start-up times and multiple versions of the same UI components.
Hey, everyone. Thank you for joining the session. Today, we are going to be taking a look at server-driven UI, how you can use it within your React Native applications to create more scalable and complex UIs and layouts without incurring a lot of cost and a lot of tech debt.
My name is Mo. I head the mobile team at Theodo. Theodo has been doing React Native since 2015, I believe. We were very early adopters as soon as React Native came out a few months after we started doing React Native. We've been hosting things like the React Native London meetup since 2017. We're very passionate about React Native. We've been in the space for a while, and we've seen a whole host of projects in the React Native space from small to large. Hopefully we can share some of that experience with you all.
The best way to talk about server-driven UI is to go through a very concrete story from the industry. Let's go back in our timelines, back from 2024 all the way to 2019. This was a simpler time. It was the age before the pandemic. Life was simple. For the folks at Facebook before they were called meta, they were just releasing out a lot of new features into the messenger app. If you remember, the logo was blue. It didn't have the gradient. They had just introduced a large group chats. They had added in new functionality and features such as polling. They even added things like maps and games into their app. This app was expanding very, very quickly. As a result, they had over 1.7 million lines of code in the iOS app for Messenger. They had a massive bundle size. We're talking 130 megabytes. All of this resulted in slow app start-up times and also slow run time of the app. There were multiple versions of the same UI components. One thing that they gave an example of was that there were 40 different contactless screens, which is really just the exact same component with slight variations. They had duplicated similar layouts across the app with very minor variations.
2. Project Lightspeed
Project Lightspeed was born as a simpler way to define layouts and UI without hard coding and duplication. The server controls the UI, resulting in a massive reduction in lines of code and bundle size. It also improved team efficiency and introduced a new logo.
Project Lightspeed was born. The whole concept behind Project Lightspeed was that they needed a simpler way to define layouts, to define the UI, that didn't require so much hard coding of different variations, so much code duplication. The strategy that they landed on was this concept of server-driven UI, with a fair bit of more complexity added in for things like caching, offline support. Really the gist of it was that the server controls the UI. If we look at the results, if we go out to 2020, what happened was those 1.7 million lines of code, they were reduced down to 360,000 lines of code. That is a massive reduction. The 130 megabytes of bundle size was reduced down to 30 megabytes of bundle size. They had an entirely new logo, right? Everyone is happy. Really, the gist of it was they were able to cut down so much, speed up their team significantly, all through adopting a different architecture and a different pattern to think about it.
Comments