#Those using Prisma; How do you make your API faster from 400ms to <100ms.

21 messages · Page 1 of 1 (latest)

white lava
#

I have been using Prisma as the ORM with my Nest.
and for basic fetching lists my API takes about 300-400 ms on Average.
So, how do I go <100ms?

tawdry sierra
#

first of all, find where's the bottleneck

white lava
#

@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

rancid wigeon
#

primsa makes migrations easy

vivid snow
vivid snow
#

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

white lava
#

Thank you @vivid snow

stoic raven
#

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.
white lava
#

This is great! @stoic raven Should help me a lot!

tawdry sierra
#

caching db queries would probably help you as well

rancid wigeon
vivid snow
stoic raven
rancid wigeon
#

The orm part is same as all orms mostly

rancid wigeon
#

I know people mention memory leaks and stuff

stoic raven
#

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.

vivid snow
#

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

rancid wigeon
#

Try it out 🤷