Prisma vs. Drizzle: What I Learned After Six Months in Production
Prisma is excellent until it isn't. After six months with Drizzle on two production apps, here's what actually changed and what I'd choose again....
In a recent six-month production run, the author compared two database libraries for serverless applications: Prisma and Drizzle. The primary reasons for switching from Prisma to Drizzle were bundle size and cold start performance. Prisma's query engine, a compiled Rust binary, added noticeable cold start time to Next.js App Router apps, which aimed to keep latency low. Drizzle, on the other hand, generated raw SQL and sent it directly to the database driver, resulting in fast cold starts and a library size of around 30KB.
One key difference between the two libraries is how they handle schema definition. Prisma uses its own schema definition language (SDL), while Drizzle defines schema directly in TypeScript. This allows for schema as code, enabling developers to import, extend, compute derived types, and use schema in conditions. Additionally, Drizzle queries are composable, allowing for conditional query building and pagination.
Migrations in Drizzle are SQL files that developers can edit, commit to git, and review. In contrast, Prisma's migrations are also SQL but can be more verbose and have opinionated tooling. Prisma's include/select API for relations is considered better than Drizzle's approach, which requires more explicit and verbose SQL joins. However, Drizzle's schema as code approach, composable queries, and SQL migration files proved advantageous for the author's specific use case.
Ultimately, for a serverless deployment with complex schema, Drizzle is recommended due to its bundle size, cold start performance, and composable queries. For simpler applications or those not on serverless, Prisma remains a viable option with a more polished developer experience and easier relation handling. The migration process from Prisma to Drizzle took about a day, with the most time-consuming part being the replacement of Prisma queries with Drizzle equivalents.
Rewritten by urgent.news; may contain errors โ check the original.
Source: hackernoon.com
Read the original at hackernoon.com โ
More from HackerNoon on urgent.news
Report a problem with this story
Get the day's news by email. Daily, weekly or monthly. Sign up