Why Prisma chose Turso to power Prisma Optimize

Cover image for Why Prisma chose Turso to power Prisma Optimize

My name is Pierre-Antoine Urvoy, and I'm one of the engineers at Prisma working on Optimize. Prisma ORM is a next generation, open source object relational mapping (ORM) tool for Node.js and TypeScript that simplifies database access and management by providing a type-safe query builder, automated migrations and more.

We recently announced Prisma Optimize, which helps developers become experts at making their queries faster. We want to educate them, but also to show them specifically what’s wrong with their queries and how to improve them. To do this we use a concept called “recordings.”

To use “recordings” you hook our Optimize extension to your app, click “Start recording” and then your queries start arriving in the dashboard. You can interact with your app as normal, and new queries will appear. When you click “End recording” is when the magic starts.

We start analyzing your queries, grouping them and then giving you recommendations on how to optimize them. For example, it’ll suggest you add an index to a specific field if you forgot an index somewhere - It’s amazing how impactful this is for people because it’s easy to overlook and the cause of many bottlenecks. Or maybe you forgot a limit, which is fine locally but not great for production, so we recommend you might want pagination. There are more dynamically generated recommendations like this, all based on smart, AI-driven query analysis.

Prisma Optimize also comes with a conversational AI assistant for natural language conversation.

#Why we chose Turso to power Prisma Optimize

Initially we were looking at time-series databases but they weren’t an exact fit for what we needed. Then we looked at another large player in the SQLite space, but we found it lacking a few key features we needed at the time, such as the ability to provision databases on the fly without triggering a redeployment, and too restrictive in terms of vendor lock in.

Turso had those capabilities, and also offered vendor flexibility while still being very compliant with SQLite. So if we needed to we could just take our SQLite-compatible libSQL file to any other SQLite vendor, or just host it locally, and all it would take is changing out the driver. Very interoperable, and it’s also compatible with most open source SQLite extensions out there, some of which we ended up using.

#How we use Turso

Turso is the backbone of our data storage engine. Using multi-schema databases, called schema dbs, we can automatically deploy database schema changes to many databases at once and within a blink. To be fair, it took us a bit to understand how Turso wanted us to do this to avoid triggering a locked state, but once we did it became extremely convenient.

Prisma Optimize is part of the Prisma Data Platform, an ecosystem of products built on top of the Prisma ORM to simplify developing data-driven applications.

The Prisma Data Platform has a concept of workspace, which is an isolated space to host projects. Turso enabled us to build our multi-tenancy model on top of workspaces, with customers in a workspace isolated per database. You can be on any of our plans and have complete isolation per workspace.

When a user tries to access Optimize for the very first time, a new database will be provisioned on the fly and then bound to its schema database, so it's already migrated on creation - and voila, we can immediately start writing to it.

The multitentancy story with Turso has been amazing and super easy to implement. It’s made permissions, especially token management, really simple.

Oh, and shout out to the Turso CLI. It’s amazing. The whole experience has been great from my perspective.

#What's next

We’ve got big plans for the future of Prisma Optimize. Right now we support a limited number of recommendations, but we have a whole laundry list of additional ones we are going to be adding to the mix.

We also currently focus mostly on recommendations around the local dev experience, but in the future we plan for this to be more useful in production workloads.

And there’s more to come.

#Conclusion

We encourage you to explore the example apps in the Prisma repo and get started with Prisma Optimize today. You’ll begin seeing improvements to your query performance in no time.

And of course stay up to date with the latest from Prisma on X/Twitter and our changelog. We’d also love to have you on our Discord.

scarf