techtales.vercel.app
My Experience with PRISMA so Far and Why I ... - Tech Tales
Excerpt
# Challenges Immediately after switching to Prisma, I realized my server was taking too long to respond. A single login request, which often took 700ms to complete, took over 10s. This delay is significant and could affect user performance. Requests made with Prisma were ten times slower than normal! I looked around to try and understand why this was happening or some errors that I could be making. Prisma documentation suggests indexing frequently queried columns such as username and email by adding @@index([username, email]). However, this does not solve the issue. Prisma is too slow, especially in queries that involve selecting data from more than one table. The database also has a cold start, which means that after the Prisma client disconnects, new requests will take time. PRISMA is also not designed to run on the edge, where vercel hosts their serveless functions. This implies that the servers are not up and running all the time in a serverless environment, thus the cold starts before Vercel spins the function and awakens the database. ## Here is what I have realized so far: - Prisma is not suited to run on the edge and thus the database sleeps when the Prisma client disconnects. Prisma takes time to connect again. - Every new insert via Prisma opened a database-level transaction (?). An extremely weird design choice by Prisma. This makes you exhaust your connection pool very fast. … - For every action (Create, Read, Update, and Delete) prisma returns the object by default even if you do not want it. Even for delete! - Prisma supports JSONB datatypes in Postgresql and MySQL. However, there is no way to update such data type. The existing way is to fetch the whole object, spread it, and then add or delete data, then post the same object again. This is utterly ridiculous.
Related Pain Points
Rust query engine incompatibility with edge runtime platforms
8The Prisma Rust query engine makes Prisma undeployable to Cloudflare Workers and other edge runtime environments, limiting platform compatibility.
Prisma's query engine fetches entire tables inefficiently, causing expensive data reads and performance degradation
7Prisma's Rust-based query engine performs application-level joins by fetching entire tables and merging results in memory rather than using optimized database-level SQL joins. This approach wastes bandwidth and becomes prohibitively expensive for teams paying per-row-read to database providers like PlanetScale, and is especially problematic at scale.
Automatic transaction wrapping exhausts connection pool
7Prisma automatically wraps every create, read, update, and delete operation in database-level transactions without option to disable, rapidly exhausting connection pools in high-concurrency scenarios.
JSONB data type updates require fetch-spread-repost pattern
6Prisma lacks native support for updating JSONB fields in PostgreSQL/MySQL, requiring developers to fetch the entire object, spread it, modify it, and re-post it instead of using direct partial updates.
Prisma always returns full objects even when not requested
4Prisma returns complete objects for all CRUD operations by default, even for delete operations where the return value is not needed, wasting bandwidth and computational resources.