But in a database, which can have many tables, each with many rows, you can't just serially run every mutation. So that's where transactions come in, and they do solve this problem. The issue with current backends is that transactions are costly and therefore optional.
It's super easy to write backend code like this, and for it to fail, not in tests, not during development, but only in production when you get sufficient write volume to get those concurrent writes to mess up each other's logic. React is designed so that transactions are cheap. This allows it to require that every endpoint that writes to the database runs as a transaction automatically, ensuring that no concurrent write can mess up its logic.
The fourth principle relates to caching. A React component is a pure function from props and state to the rendered UI. And this allows us to cache rendering of components easily with React memo. That leads to improved performance. Caching is even more important on the backend, where it's the server owner, sometimes us, paying the computation cost, not the user. But caching today on the backend is hard because cache invalidation is not automatic. Take the to-do list example. We want to cache the list of to-dos but when a new item is added, a traditional backend doesn't know it needs to invalidate the cache. Again, we need to instruct it manually. So convex's database tracks which writes impact which reads, and in convex, read endpoints are pure functions from database state to the result. Therefore, if no relevant writes happen, the read endpoint can be cached automatically and with perfect caching validation.
The final principle I'll mention is that React is just JavaScript, right? And this principle gives React several great properties. It is highly composable, easy to build on top of, and comes with great optional type checking, thanks to TypeScript, as we've heard before. And JavaScript is getting ever more popular on the backend, which is great, but when it comes to databases, the most popular options seem to be Postgres and MySQL. And SQL is the opposite of JavaScript. It is hard to compose, hard to build on top of, and has no static type checking itself. And this lack of composability leads to complex queries which the database tries to optimize, which then leads to unpredictable performance. And this is why the API from the convex database is just JavaScript. It is simple, highly composable, easy to build on top of, and fully typed, allowing end-to-end type safety all the way to the client. And convex combines the best of SQL and NoSQL databases being relational and yet not requiring you to define a schema upfront.
So taking these five React principles and applying them to the full stack radically simplifies the building of apps and enables a better UX. And of course, this backend needs to scale with your needs. So we are building such a backend at convex. It is fully open source, comes with a dashboard, and a bunch of features, text search, file storage, scheduling, more that I didn't get to talk about.
Comments