#Those using Prisma; How do you make your API faster from 400ms to <100ms.
21 messages · Page 1 of 1 (latest)
first of all, find where's the bottleneck
@tawdry sierra we added prisma on an existing DB which was very poorly designed. So, we there are a lot of places where joins aren’t possible. So we are having to do a lot iterations to get the data
primsa makes migrations easy
What does this have to do with the current conversation?
As for how to make your API faster, well, if you have an inefficient database, there's only so much you'll be able to do without a redesign of the database schema and fixing up the data relations
Thank you @vivid snow
Steps for analyzing/improving performance:
- figure out the bottleneck - is it the app or the DB?
- Implement tracing with OpenTelemetry so you can see how long certain actions take
- If you find out that it's the database calls, log the actual DB query and analyze it against the database (if you use Postgres, use EXPLAIN)
- If you fund out it's the application, figure out how to refactor the logic or possibly scale the app horizontally or vertically depending on the load.
This is great! @stoic raven Should help me a lot!
caching db queries would probably help you as well
If your db is poorly designed and you've adopted prisma, redesigning your tables is trivial and really the only solution for op
It handles schema and data migrations? What about joins vs n+1? Practically everything I've seen in practice is that prisma looks great on the surface but suffers in actual performance, much like almost any ORM out there
redesigning your tables is trivial
Unless you have production data already in the database. Data migrations are PAIN
thats the big benefit isn't it? It gens sql to migrate tables
The orm part is same as all orms mostly
I don't use it a ton, but I haven't had any issues
I know people mention memory leaks and stuff
I mean don't get me wrong, I think that Prisma is amazing for what it does. For what it doesn't do, you can use another query builder to compose an optimized query and just use prisma to call the query. However, calling redesigning a table schema trivial is quite far-fetched. Last I checked, Prisma didn't support data migrations an still, if they care about backwards compatibility, migrating data is far from a trivial endeavor.
I can write a schema migration with Kysely (query builder) no problem. But I still have to write the data migration to change the data in the database from one type to another or to move it from table to table as the entire schema changes. If you're telling me prisma will correctly and accurately move that data for me, I'd probably call you a liar as that is usually beyond the scope of most automated migrations
Try it out 🤷