Handling Data at Scale for React Developers

Rate this content
Bookmark

It is very difficult to scale modern web applications to millions of concurrent users. Oftentimes, we've got to provision and consider in-memory Key/Value stores, search engines, analytics engines, and databases, all while preserving traceability through the layers. This talk expands on the technical details of web apps at this scale, and offers a simpler way to achieve the same effect without the technical hassle.

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

FAQ

The main topic of the talk given by Tajus is handling data at scale for React developers.

The presentation slides for Tajus's talk were created by Sarah Vieira.

Tajus used an amazing tool called Excalidraw to illustrate data at scale in his talk.

The three ways to fetch data in React discussed by Tajus are: 1. Render then fetch, 2. Fetch then render, 3. Render as you fetch.

The purpose of using the useTransition hook in React 18 is to differentiate between urgent and non-urgent updates. It allows React to prioritize urgent updates (like user interactions) over non-urgent ones (like data fetching), thereby improving user experience by reducing jank.

The common steps to scale a database as described by Tajus include: 1. Distributing the API to avoid a single point of failure, 2. Scaling the database vertically by adding memory and disk space, 3. Scaling the database horizontally by adding primary instances and replicas, 4. Using an in-memory database to speed up data reading, 5. Adding a search engine to handle large data volumes and replicating data in real-time using tools like Kafka.

The recommended way to implement 'render as you fetch' in production, according to Tajus, is to use a framework or library that is battle-tested and handles edge cases, such as Next.js or Remix, rather than implementing it manually.

The key takeaway from Tajus's talk about handling data at scale in React is to understand the different strategies for data fetching (render then fetch, fetch then render, render as you fetch) and the importance of using frameworks and libraries to handle complex data fetching scenarios efficiently. Additionally, he emphasizes the use of React 18's concurrent features to improve performance and user experience.

The role of suspense in React 18 for data fetching is to allow React to pause rendering at specific points in the component tree if the data required for a component is not yet available. This enables better control over loading states and improves the overall user experience by showing fallbacks or placeholders until the data is ready.

'Render as you fetch' in React 18 means that React starts rendering a component and, when it reaches a component that is not yet ready because it doesn't have data, React pauses rendering that component and continues rendering the rest of the tree. Once the data is ready, React goes back and renders the paused component.

Tejas Kumar
Tejas Kumar
23 min
17 Jun, 2022

Comments

Sign in or register to post your comment.
Video Summary and Transcription
This Talk discusses handling data at scale for React developers, including scaling databases and the need for search. It explores different ways to fetch data in React, such as using useEffect, fetch, and setState. The Talk also introduces Suspense for data fetching and how it improves user experience. It covers controlling React Suspense, handling search, and using render-as-you-fetch. The Talk concludes with a discussion on the RFC status and fetching in event handlers.

1. Handling Data at Scale for React Developers

Short description:

We're here to talk about handling data at scale for react developers. Let's get more specific with that and actually look at a diagram of what we mean by data at scale. Usually, you have a React app or React UI that talks to an API that then talks to a database. At some point, you're going to experience growth and performance becomes important. So you distribute your API, have multiple APIs, and load balance between them. But if you're successful, your database may become the bottleneck, so you need to scale it.

I was totally playing that guitar. Hi! How are you? Full? Full from lunch? Satisfied? A little more knowledge and information and fun react things? It's like three of you, three of you are awake. Four? Again, how are you feeling? Are you ready to take in some stuff? Off by one errors, you know?

Anyway, Hi! Nice to see you! I'm Tajus, I used to tell people. I used to tell people it's like something, but now I say like advantageous. Anyway, so I'm the director of developer relations at Zara. Look at this beautiful thing. That is my favorite slide and also one of my five slides I have. We're going to be writing a lot of code in this talk and learning properly. This by the way was by Sarah Vieira, she's here, she's doing the last talk today, so catch that if you want to learn how to do 3D stuff. But that's not what we're here to talk about today.

We're here to talk about handling data at scale for react developers. Handling data at scale for react developers. What does that mean? This sounds like a very abstract marketing talk and the answer is because it's not a marketing talk but it is abstract on purpose so that I can change it at the last minute as I always do, okay? But let's get more specific with that and actually look at a diagram of what we mean by data at scale. To do that, we're going to use an amazing tool called Excalidraw. How many of you have heard of Excalidraw? Yeah, if you want to applaud Excalidraw, yeah, for sure. Data at scale. This is what it looks like. Usually, you have a React app or React UI, let's say, right? Is the text okay? Can you all see? Good. I knew. I just asked and what we're going to do is you usually have a React UI that talks to an API that, let's zoom out a little bit, that then talks to a database and these connections usually look a little bit like this. So this maybe oversimplified, but that is most applications. Is this at scale? Probably not. This is a single host database and so on. At some point, you're going to experience like, we're growing and performance is important. So what do you do? You probably will distribute your API. Having a single point of failure is usually a no-no, so what you'll do is you'll do that and you'll have multiple APIs that can fetch multiple times and whatever. And you can load balance between them. And then, OK, you're like, this is cool, but you're going to, if you're successful, what do successful things do? They grow. So if you grow, you're going to be like, oh no, our database is now the bottleneck. Let's make it, let's scale it.

2. Scaling Databases and the Need for Search

Short description:

So you'll scale your database vertically or horizontally. Scaling vertically means adding memory and disk space, while scaling horizontally involves having a primary instance and replicas. As your data grows, you may notice slow reading times from the database due to disk limitations. To address this, you can add an in-memory database for faster reading, with the option to fall back to the disk if there's a cache miss. Eventually, as your data volume increases, search becomes a common feature needed for platforms like GitHub, TikTok, and Instagram.

So you'll scale it vertically. And this vertical scale usually means adding memory, adding disk space, adding stuff. And it gets quite expensive. You eventually build a supercomputer. Or, if you want to scale your database the other way, you scale horizontally, meaning you have maybe a primary instance and some replicas. So when you get data, it spreads out across the replicas and so on and so forth.

But then you're going to grow more. And we're talking about data at scale, so it's important to establish this context. You're going to grow a little bit more. At some point, you're going to be like, wait, our database is still, reading from it is slow. And that's because usually databases read from disk. Disk by design is not as fast as what? Memory. Memory. So, let's now, this, I've had this conversation, like, at least 50 times in the past week. That's a lie because I'm a public speaker. I really haven't. But you know how it is.

So, you'll add some type of in-memory database just to read from it faster. This will probably be distributed as well. And so now your app will talk to that thing to get data fast. And if it's a cache miss, then you read from the database. Okay? This is close to what things look like at scale. I think Kent C. Dodd's website has something like this in the back. But as you accumulate now data volume, what is the one common feature across things with a ton of data volume? Search. So, GitHub, TikTok, Instagram. Eventually, when you get enough data, you're going to need search. And so now it gets complicated, right? Because your app can read from the search engine, but it's gonna be empty. You're just like... Okay.

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

Don't Solve Problems, Eliminate Them
React Advanced 2021React Advanced 2021
39 min
Don't Solve Problems, Eliminate Them
Top Content
Kent C. Dodds discusses the concept of problem elimination rather than just problem-solving. He introduces the idea of a problem tree and the importance of avoiding creating solutions prematurely. Kent uses examples like Tesla's electric engine and Remix framework to illustrate the benefits of problem elimination. He emphasizes the value of trade-offs and taking the easier path, as well as the need to constantly re-evaluate and change approaches to eliminate problems.
Jotai Atoms Are Just Functions
React Day Berlin 2022React Day Berlin 2022
22 min
Jotai Atoms Are Just Functions
Top Content
State management in React is a highly discussed topic with many libraries and solutions. Jotai is a new library based on atoms, which represent pieces of state. Atoms in Jotai are used to define state without holding values and can be used for global, semi-global, or local states. Jotai atoms are reusable definitions that are independent from React and can be used without React in an experimental library called Jotajsx.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
The Epic Stack
React Summit US 2023React Summit US 2023
21 min
The Epic Stack
Top Content
Watch video: The Epic Stack
This Talk introduces the Epic Stack, a project starter and reference for modern web development. It emphasizes that the choice of tools is not as important as we think and that any tool can be fine. The Epic Stack aims to provide a limited set of services and common use cases, with a focus on adaptability and ease of swapping out tools. It incorporates technologies like Remix, React, Fly to I.O, Grafana, and Sentry. The Epic Web Dev offers free materials and workshops to gain a solid understanding of the Epic Stack.
Principles for Scaling Frontend Application Development
React Summit 2023React Summit 2023
26 min
Principles for Scaling Frontend Application Development
Top Content
Watch video: Principles for Scaling Frontend Application Development
This Talk discusses scaling front-end applications through principles such as tearing down barriers, sharing code in a monorepo, and making it easy to delete code. It also emphasizes incremental migration, embracing lack of knowledge, and eliminating systematic complexity. The Talk highlights the use of automation in code migration and the importance of removing barriers to enable smoother code migration.
Fighting Technical Debt With Continuous Refactoring
React Day Berlin 2022React Day Berlin 2022
29 min
Fighting Technical Debt With Continuous Refactoring
Top Content
Watch video: Fighting Technical Debt With Continuous Refactoring
This Talk discusses the importance of refactoring in software development and engineering. It introduces a framework called the three pillars of refactoring: practices, inventory, and process. The Talk emphasizes the need for clear practices, understanding of technical debt, and a well-defined process for successful refactoring. It also highlights the importance of visibility, reward, and resilience in the refactoring process. The Talk concludes by discussing the role of ownership, management, and prioritization in managing technical debt and refactoring efforts.

Workshops on related topic

React, TypeScript, and TDD
React Advanced 2021React Advanced 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Web3 Workshop - Building Your First Dapp
React Advanced 2021React Advanced 2021
145 min
Web3 Workshop - Building Your First Dapp
Top Content
Featured WorkshopFree
Nader Dabit
Nader Dabit
In this workshop, you'll learn how to build your first full stack dapp on the Ethereum blockchain, reading and writing data to the network, and connecting a front end application to the contract you've deployed. By the end of the workshop, you'll understand how to set up a full stack development environment, run a local node, and interact with any smart contract using React, HardHat, and Ethers.js.
Remix Fundamentals
React Summit 2022React Summit 2022
136 min
Remix Fundamentals
Top Content
Featured WorkshopFree
Kent C. Dodds
Kent C. Dodds
Building modern web applications is riddled with complexity And that's only if you bother to deal with the problems
Tired of wiring up onSubmit to backend APIs and making sure your client-side cache stays up-to-date? Wouldn't it be cool to be able to use the global nature of CSS to your benefit, rather than find tools or conventions to avoid or work around it? And how would you like nested layouts with intelligent and performance optimized data management that just works™?
Remix solves some of these problems, and completely eliminates the rest. You don't even have to think about server cache management or global CSS namespace clashes. It's not that Remix has APIs to avoid these problems, they simply don't exist when you're using Remix. Oh, and you don't need that huge complex graphql client when you're using Remix. They've got you covered. Ready to build faster apps faster?
At the end of this workshop, you'll know how to:- Create Remix Routes- Style Remix applications- Load data in Remix loaders- Mutate data with forms and actions
Vue3: Modern Frontend App Development
Vue.js London Live 2021Vue.js London Live 2021
169 min
Vue3: Modern Frontend App Development
Top Content
Featured WorkshopFree
Mikhail Kuznetsov
Mikhail Kuznetsov
The Vue3 has been released in mid-2020. Besides many improvements and optimizations, the main feature of Vue3 brings is the Composition API – a new way to write and reuse reactive code. Let's learn more about how to use Composition API efficiently.

Besides core Vue3 features we'll explain examples of how to use popular libraries with Vue3.

Table of contents:
- Introduction to Vue3
- Composition API
- Core libraries
- Vue3 ecosystem

Prerequisites:
IDE of choice (Inellij or VSC) installed
Nodejs + NPM
React at Scale with Nx
React Summit 2023React Summit 2023
145 min
React at Scale with Nx
Top Content
Featured WorkshopFree
Isaac Mann
Isaac Mann
We're going to be using Nx and some its plugins to accelerate the development of this app.
Some of the things you'll learn:- Generating a pristine Nx workspace- Generating frontend React apps and backend APIs inside your workspace, with pre-configured proxies- Creating shared libs for re-using code- Generating new routed components with all the routes pre-configured by Nx and ready to go- How to organize code in a monorepo- Easily move libs around your folder structure- Creating Storybook stories and e2e Cypress tests for your components
Table of contents: - Lab 1 - Generate an empty workspace- Lab 2 - Generate a React app- Lab 3 - Executors- Lab 3.1 - Migrations- Lab 4 - Generate a component lib- Lab 5 - Generate a utility lib- Lab 6 - Generate a route lib- Lab 7 - Add an Express API- Lab 8 - Displaying a full game in the routed game-detail component- Lab 9 - Generate a type lib that the API and frontend can share- Lab 10 - Generate Storybook stories for the shared ui component- Lab 11 - E2E test the shared component
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
JSNation 2023JSNation 2023
174 min
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
Top Content
Featured WorkshopFree
Alba Silvente Fuentes
Roberto Butti
2 authors
This SvelteKit workshop explores the integration of 3rd party services, such as Storyblok, in a SvelteKit project. Participants will learn how to create a SvelteKit project, leverage Svelte components, and connect to external APIs. The workshop covers important concepts including SSR, CSR, static site generation, and deploying the application using adapters. By the end of the workshop, attendees will have a solid understanding of building SvelteKit applications with API integrations and be prepared for deployment.