Applying React Principles to a Cloud Database

Rate this content
Bookmark

What would a backend look like if it was designed with modern React applications in mind? What could the database do if it followed core React principles? Learn about a new approach to building fullstack apps with a reactive database in this lightning talk.

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

FAQ

Besides its core functionalities, Convex offers a dashboard, text search, file storage, scheduling, and more. It is also fully open source.

Convex applies React principles to the full stack, simplifying app development and improving user experience. It ensures reactivity, consistency, handles overlapping writes efficiently, manages caching automatically, and provides a highly composable JavaScript API.

Yes, Convex is fully open source and comes with a bunch of features like a dashboard, text search, file storage, and scheduling.

By applying React principles such as reactivity, consistency, efficient overlapping writes, automatic caching, and a composable JavaScript API, Convex radically simplifies the building of apps and enables a better user experience.

Convex builds endpoints that are as reactive as your state. When data is written into the database, Convex automatically figures out which data needs updating, pushes these updates to all clients, and triggers React to re-render automatically.

Convex ensures consistency by figuring out which data reads need updating when changes occur and pushing these updates together to the client. This ensures that React renders a consistent result in a single pass.

Overlapping writes can cause concurrency issues where multiple writes mess up each other's logic. Convex solves this by making transactions cheap and requiring every endpoint that writes to the database to run as a transaction automatically.

Convex tracks which writes impact which reads, allowing read endpoints to be pure functions from database state to the result. This makes cache invalidation automatic and enables perfect caching validation.

Convex's API is based on JavaScript because it is simple, highly composable, easy to build on top of, and fully typed, allowing for end-to-end type safety. This approach combines the best of SQL and NoSQL databases without requiring a schema upfront.

Convex is a backend and database solution designed to carry forward React principles to the full-stack developer and user experience. It aims to solve issues like reactivity, consistency, overlapping writes, caching, and composability that arise when building full-stack applications.

Michal Srb
Michal Srb
7 min
14 Jun, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
React principles can break down for full-stack apps, but Convex has built a backend and database to address this. The five React principles discussed include reactivity, consistency, overlapping writes, and caching. Convex's database ensures consistency, handles overlapping writes with transactions, and automatically invalidates caches based on relevant writes. Convex combines the best of SQL and NoSQL databases and applies React principles to simplify app development and improve the user experience.

1. Introduction to Convex and React Principles

Short description:

React has revolutionized the way we build interactive front ends for our apps. Convex has built a back end and a database that carries React principles to the full-stack developer and user experience. The first principle is reactivity, allowing you to build endpoints as reactive as your state. The second principle is consistency, ensuring a consistent view even with separate data fetches. The third principle deals with overlapping writes, guaranteeing correct updates even with multiple state updates.

Hi, everyone. I'm Michael. I'm a software engineer at Convex. I've been building full-stack apps for over 15 years. And as you all probably know, React has revolutionized the way we build interactive front ends for our apps.

But when it comes to building full-stack apps for multiple users interacting with each other, the React principles that help us build great front ends kind of break down. So at Convex, we set out to build a back end and a database that carries these principles to the full-stack developer and user experience. And today I'll talk about five of these React principles, and each is solving a problem that I'm sure many of you have encountered.

So the first principle is reactivity. We're going to build a todo app in React, everyone's favorite demo. So what happens when I tap into todo and hit enter? I update my state, and React automatically renders the list of todos. Super easy. But what about if I want to store the list of todos in a database? I'm going to need a read endpoint and a write endpoint, and when I hit enter, I call my write endpoint, but nothing actually happens automatically. I'll have to instruct React or my framework to refetch the read endpoint, and this can get quite difficult and complex as apps grow in complexity, and it won't even work at all if another user is the one adding the todo into the list. So with Convex, you can build endpoints which are as reactive as your state. In this example, I just write the todo into the database, and the database figures out for me that the list of todos needs updating, pushes the updates to all clients, and those trigger React to re-render automatically. And that's all it takes.

The second principle is consistency. I don't know about you, but inconsistent UIs frustrate me. Have you ever been on Slack or Instagram and there's a red badge and you click on that icon and you open a list and there's nothing there? Well, the reason that happens is because that red badge and the list in the tray are powered by different backend endpoints and they're fetched separately. So client-side React itself doesn't have this problem. If you have some state and then you're rendering a tree of React components, the view you get is always consistent. But once we add a database and we separate the data fetches, you might get an inconsistent view from your database. So Convex, on the other hand, is always consistent. In this example, when the data changes, the database figures out that those two reads need updating and pushes the update together to the client, and then the client instructs React to render a consistent result in a single pass.

The third principle has to do with overlapping writes. The simplest example you can demonstrate this on is incrementing a counter. You need the current value and then you update the counter to the current value plus one. And in React, we can ensure that this always works correctly even if there are multiple places where the state can be updated, multiple state updates together by passing an updater function to the set function. React then runs all state updates serially so that two updates can't mess up each other's logic.

1. Introduction to React Principles and Convex

Short description:

Hi, everyone. I'm Michael, a software engineer at Convex. React revolutionized front-end development, but its principles break down for full-stack apps with multiple user interactions. At Convex, we built a back end and database to address this. Today, I'll discuss five React principles, each solving common problems. The first is reactivity. By utilizing Convex, you can build reactive endpoints that automatically update the state and trigger React to re-render.

Hi, everyone. I'm Michael. I'm a software engineer at Convex. I've been building full-stack apps for over 15 years. And as you all probably know, React has revolutionized the way we build interactive front ends for our apps.

But when it comes to building full-stack apps for multiple users interacting with each other, the React principles that help us build great front ends kind of break down. So at Convex, we set out to build a back end and a database that carries these principles to the full-stack developer and user experience. And today I'll talk about five of these React principles, and each is solving a problem that I'm sure many of you have encountered.

So the first principle is reactivity. We're going to build a todo app in React, everyone's favorite demo. So what happens when I tap into todo and hit enter? I update my state, and React automatically renders the list of todos. Super easy. But what about if I want to store the list of todos in a database? I'm going to need a read endpoint and a write endpoint, and when I hit enter, I call my write endpoint, but nothing actually happens automatically. I'll have to instruct React or my framework to refetch the read endpoint, and this can get quite difficult and complex as apps grow in complexity, and it won't even work at all if another user is the one adding the todo into the list. So with Convex, you can build endpoints which are as reactive as you state. In this example, I just write the todo into the database, and the database figures out for me that the list of todos needs updating, pushes the updates to all clients, and those trigger React to re-render automatically. And that's all it takes.

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

Serverless in Production, Lessons from the Trenches
Node Congress 2022Node Congress 2022
34 min
Serverless in Production, Lessons from the Trenches
This Talk provides valuable insights for those considering serverless in 2022, with a focus on troubleshooting and observability using Lumigo. It emphasizes the use of multiple AWS accounts and Org Formation for better control and scalability. Security considerations include securely loading secrets at runtime and implementing zero-trust networking. Optimizing Lambda performance is discussed, along with updates on serverless frameworks and the role of Terraform. The Talk also compares Honeycomb and Lumigo for observability in serverless applications.
Building full-stack applications on the Edge
React Advanced 2022React Advanced 2022
9 min
Building full-stack applications on the Edge
This Talk explores building full stack applications on the edge and the blurring line between front end and back end development. It discusses the benefits of using the JAMstack and APIs for scalable web development. The Talk also highlights the improvements in edge technology, such as serverless functions and efficient data storage, and the deployment of functions and durable objects on the edge network. Overall, the Talk emphasizes the importance of delivering high-quality experiences with low latency through edge computing.
Turning the Cloud Inside Out
React Summit Remote Edition 2021React Summit Remote Edition 2021
36 min
Turning the Cloud Inside Out
Today's Talk discusses turning the cloud inside out using GraphQL, highlighting its benefits such as type validation, real-time capabilities, and query efficiency. It explores the use of GraphQL as an API gateway, particularly in the context of microservices, third-party APIs, and blockchain. The talk also covers the efficient indexing and cloud integration offered by GraphQL, as well as building cloud APIs with AWS using API Gateway and AWS AppSync. It concludes with insights on deploying GraphQL APIs with tools like Amplify and CDK, and creating GraphQL APIs backed by Lambda and DynamoDB.
Game Changer! Building Search Into Your Applications
Node Congress 2023Node Congress 2023
8 min
Game Changer! Building Search Into Your Applications
Implementing the right strategies and tools, such as Apache Lucene, can improve search performance and user experience. The choice of analyzer affects search results, and query operators provide various search options. Relevant scoring is crucial for ranking documents based on relevance. Custom scoring can prioritize specific criteria. Consider analyzers, query operators, and scoring methods to optimize the search experience.
Running TypeScript in WebAssembly on the Cloud
TypeScript Congress 2023TypeScript Congress 2023
10 min
Running TypeScript in WebAssembly on the Cloud
Today's Talk discusses running TypeScript in WebAssembly on the cloud using Fermion's WebAssembly runtime. Fermion provides a serverless environment called Spin that allows for easy serverless application development in multiple languages. The process of creating a TypeScript serverless app with Spin involves installing Spin, creating a new app using the HTTP TS template, and testing it on localhost. To deploy the app, the 'spin deploy' command is used, and Fermi on cloud handles routing and makes the app accessible through a public URL.
Pushing Boundaries To The Edge
React Summit 2023React Summit 2023
9 min
Pushing Boundaries To The Edge
Watch video: Pushing Boundaries To The Edge
The Talk discusses the concept of the Edge and its role in content delivery networks (CDNs). CDNs are designed to improve the delivery of static content but cannot distribute dynamically generated content. Edge computing is a distributed network architecture that processes data close to the source or users, enabling personalization, geolocation-based dynamic content, AV testing, and content authentication. Frameworks like NexGIS, Bercel, Netlify, AWS, and Remix offer edge computing capabilities through edge functions or middleware, allowing execution of server-side logic closer to end users.

Workshops on related topic

Build and Deploy a Backend With Fastify & Platformatic
JSNation 2023JSNation 2023
104 min
Build and Deploy a Backend With Fastify & Platformatic
WorkshopFree
Matteo Collina
Matteo Collina
Platformatic allows you to rapidly develop GraphQL and REST APIs with minimal effort. The best part is that it also allows you to unleash the full potential of Node.js and Fastify whenever you need to. You can fully customise a Platformatic application by writing your own additional features and plugins. In the workshop, we’ll cover both our Open Source modules and our Cloud offering:- Platformatic OSS (open-source software) — Tools and libraries for rapidly building robust applications with Node.js (https://oss.platformatic.dev/).- Platformatic Cloud (currently in beta) — Our hosting platform that includes features such as preview apps, built-in metrics and integration with your Git flow (https://platformatic.dev/). 
In this workshop you'll learn how to develop APIs with Fastify and deploy them to the Platformatic Cloud.
Deploying React Native Apps in the Cloud
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
WorkshopFree
Cecelia Martinez
Cecelia Martinez
Deploying React Native apps manually on a local machine can be complex. The differences between Android and iOS require developers to use specific tools and processes for each platform, including hardware requirements for iOS. Manual deployments also make it difficult to manage signing credentials, environment configurations, track releases, and to collaborate as a team.
Appflow is the cloud mobile DevOps platform built by Ionic. Using a service like Appflow to build React Native apps not only provides access to powerful computing resources, it can simplify the deployment process by providing a centralized environment for managing and distributing your app to multiple platforms. This can save time and resources, enable collaboration, as well as improve the overall reliability and scalability of an app.
In this workshop, you’ll deploy a React Native application for delivery to Android and iOS test devices using Appflow. You’ll also learn the steps for publishing to Google Play and Apple App Stores. No previous experience with deploying native applications is required, and you’ll come away with a deeper understanding of the mobile deployment process and best practices for how to use a cloud mobile DevOps platform to ship quickly at scale.
Full Stack GraphQL In The Cloud With Neo4j Aura, Next.js, & Vercel
GraphQL Galaxy 2021GraphQL Galaxy 2021
161 min
Full Stack GraphQL In The Cloud With Neo4j Aura, Next.js, & Vercel
WorkshopFree
William Lyon
William Lyon
In this workshop we will build and deploy a full stack GraphQL application using Next.js, Neo4j, and Vercel. Using a knowledge graph of news articles we will first build a GraphQL API using Next.js API routes and the Neo4j GraphQL Library. Next, we focus on the front-end, exploring how to use GraphQL for data fetching with a Next.js application. Lastly, we explore how to add personalization and content recommendation in our GraphQL API to serve relevant articles to our users, then deploy our application to the cloud using Vercel and Neo4j Aura.

Table of contents:
- Next.js overview and getting started with Next.js
- API Routes with Next.js & building a GraphQL API
- Using the Neo4j GraphQL Library
- Working with Apollo Client and GraphQL data fetching in Next.js
- Deploying with Vercel and Neo4j Aura
Declarative Infrastructure: Rethinking Cloud Native for JS
DevOps.js Conf 2024DevOps.js Conf 2024
29 min
Declarative Infrastructure: Rethinking Cloud Native for JS
Workshop
André Eriksson
André Eriksson
In this talk we uncover what Declarative Infrastructure means, and how it can work in TypeScript to naturally express higher-level distributed systems concepts (such as backend services, API calls, database queries, Pub/Sub messaging, caching and more), through the power of static analysis and code generation.The outcome is a fully reimagined DevOps process, with automatic infrastructure provisioning and built-in observability, that deploys straight to your own cloud.
Table of contents:- Introduction- Evolution of backend development, from servers to today's cloud-native world powered by DevOps and GitOps- What is Cloud Native, and how do we build modern backend applications? (Showing a microservices architecture powered by Express.js and Terraform)- What is Declarative Infrastructure? What does the space look like?- What problems does it solve compared to traditional DevOps practices?- How does it relate to Terraform/AWS CDK for infrastructure provisioning?- What are the downsides?- Building a Cloud Native backend with Declarative Infrastructure
How to Troubleshoot API Errors and Reduce MTTD/R
Node Congress 2021Node Congress 2021
149 min
How to Troubleshoot API Errors and Reduce MTTD/R
Workshop
Gal Bashan
Gal Bashan
The benefits of Node.js to develop real-time applications at scale are very well known. As Node.js architectures get more and more complex, visualization of your microservices-based architecture is crucial. However, the visualization of microservices is incredibly complex given the scale and the transactions across them. In this workshop, you will learn how to leverage service maps to instantly understand your architecture and troubleshoot any API error.

We will write a simple Express application and explore best practices when using Express. Then, we’ll deploy the application on AWS, integrate the environment with Epsagon, and deep-dive into various features of the platform to enable immediate detection and fast troubleshooting of application errors. Goals: Visualizing your architecture, monitoring your applications, reducing your mean time to detection and recovery (MTTD and MTTR).
Who should attend?
DevOps, Engineers, Cloud Architects, IT, Software Developers, Solution Architects and Engineers, SREs, and anyone who is running microservice-based applications (Kubernetes, containers, serverless functions, and more) in the cloud.

PrerequisitesWe prefer to use VSCode for a better experience (other IDEs are fine)Preinstall npm and node        Pre-existing AWS Account - You can create a free tier here        Attendees are free to create an Epsagon account in advance here, not mandatory