Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADR]: migrate ORM from Prisma to Drizzle #49

Open
JowiAoun opened this issue Aug 9, 2024 · 0 comments · May be fixed by #75
Open

[ADR]: migrate ORM from Prisma to Drizzle #49

JowiAoun opened this issue Aug 9, 2024 · 0 comments · May be fixed by #75
Assignees
Labels
backend Backend related documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers

Comments

@JowiAoun
Copy link
Collaborator

JowiAoun commented Aug 9, 2024

Problem Statement
Currently, we are using Prisma for an ORM. This issue explains how a migration to Drizzle will help us down the line. Bellow are comparisons of the two in order of importance, for our use case. Note that this may not be extensive, and comments bellow are encouraged.

Comparisons

Feature Description
Performance ⚡ On all benchmarks, Drizzle excels over Prisma, part of the reason being that Drizzle is a much thinner layer over the database, as opposed to Prisma, and is built performance first. Take it with a grain of salt, but Drizzle has benchmarks comparing it to Prisma. The software running the benchmark is also open source with backers and general agreeance. The bench marks calculated an average latency improvement of x165. Drizzle does also excel in requests per second by almost x4. CPU load is also important for us to stay within free tiers for our cloud providers, here with almost a x2.5 decrease. image
N+1 Problem 🧮 For a single query and depending how they are written, Prisma may run many additional queries to complete the request. On the other hand, Drizzle will always run a single database query. This is directly linked to performance.
Cold start 🥶 Cold start is how much time does it take to query the database when it is started up. If we decide to go serverless with AWS Fargate-ECS, Drizzle has a much better cold start time than Prisma. It has been a known issue for many years, and although Prisma attempts to fix those, there does not seem to be an end to it.
Magic factor 🪄 Prisma does a bunch of magic behind the scenes. That could be good in some cases, but in others we don't fully understand what we expect it to do. For example, a migration in PR #12 had come up with an index on the new model's attribute, Team.name, which was only caught by a reviewer, although none were created in the schema. Another example is that renaming a column can get confounded with creating a new column, which clears the database. Drizzle allows renaming a column without this happening. Of course there are many more problems that can arise by letting the ORM fully decide what happens. To back up all of this, Drizzle currently has 800 issues, while Prisma has 3000 🤯. Different number of downloads, but the percentage of issues are currently much higher on Prisma's side. I would argue that Drizzle's "lack of magic" makes it clear what is going on behind the code.
Developer Experience 💻 Prisma is a higher abstraction than Drizzle. Drizzle is closer to SQL. The effect of that on DX is that there will be slightly more code to write for Drizzle, but I would argue it is beneficial to keep the schemas verbose. Also gives a TypeScript flavour. We'll most likely use Zod and it will feel quite similar to that.
Bundle Size 📦 Cool open source tool I found while researching for this issue: Bundlephobia. Bundle size for Drizzle is 60x to 80x smaller than Prisma, depending on compression method.
Limitations ⛔ Prisma has limitations set in place, for example, unable to run raw, type safe, SQL queries. I've also run into an issue where a 1-to-1 relation non-nullable condition cannot be enforced on the database level. Drizzle does have a lot of flexibility.
Documentation 📄 Drizzle loses the battle in initial setup documentation, which won't be an issue for too long. Otherwise both have great documentation.

Solution Summary

Solution
To migrate to Drizzle, we would need to update the following:

  • Rip out Prisma & install Drizzle ORM
  • NextAuth adapter with Drizzle's adapter
  • All database calls
  • README instructions
  • Create initial migration

Other options considered
Considered staying with Prisma, but for the above reasons and as it is still early for us, we are able to proceed with a migration.

@JowiAoun JowiAoun added documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers backend Backend related labels Aug 9, 2024
@JowiAoun JowiAoun self-assigned this Aug 9, 2024
@JowiAoun JowiAoun linked a pull request Aug 27, 2024 that will close this issue
@JeremyFriesenGitHub JeremyFriesenGitHub changed the title [ADR] Migrate ORM from Prisma to Drizzle [ADR]: Migrate ORM from Prisma to Drizzle Sep 9, 2024
@JeremyFriesenGitHub JeremyFriesenGitHub changed the title [ADR]: Migrate ORM from Prisma to Drizzle [ADR]: migrate ORM from Prisma to Drizzle Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers
Projects
Status: ⏭ Todo
Development

Successfully merging a pull request may close this issue.

1 participant