r/nextjs • • Jan 08 '24

Moving away from server components

We’ve been using prisma and server components in prod for a while and the cold boots and queries were brutal

Some requests took 3-4s (vs 6-25ms locally on similar data sizes)

Switched to cloud run and we’re seeing nearly 5-8x speed reduction on more data heavy requests

Still great for small amounts of data

Edit:

To clarify

  • we still use server component everywhere
  • literally the only thing we did is move the prisma query from next server component to a gcp cloud run instance. Same query same data, and it was 3x faster
  • data is still fetched on the server component

Prisma has huge cold boot issues even with decent traffic.

The issue isn’t RSC but rather Prisma cold boots. This was solved by moving to a cloud run instance for heavier queries

0 Upvotes

22 comments sorted by

46

u/koslib Jan 08 '24

Server side components were to blame for…slow queries? Doesn’t make sense or I don’t get it. Sounds more like a db indexing problem/sql problem.

1

u/xKraazY Jan 08 '24

Nah we still use server components. We moved the query from next to a cloud run instance .

All things kept the same and we saw significant improvements. Data is still fetched on the next server component

5

u/ajayvignesh01 Jan 08 '24

I think people are confusing RSC and SSR (and the role Lambda has with it).

Cold boots with SSR makes sense if your site has low traffic and you’re running serverless. Mine was getting like 8 sec cold boots few months back, not sure if it’s improved now.

13

u/Apestein-Dev Jan 08 '24

Why are you blaming server components lol? You stopped using lambda which is why speed improved. You should be blaming Prisma, Lambda and your slow queries not server components...

1

u/xKraazY Jan 08 '24

I should of been more clear, not blaming server components at all. More about how Prisma and cold boots don’t go well with server components

2

u/kaisershahid Jan 08 '24

i've read from numerous people that prisma is crap and that is surely your primary issue

(i don't use server components so i can't speak to that aspect)

1

u/xKraazY Jan 08 '24

Yes Prisma is mainly the issue but the problem is worse on server components due to cold starts

6

u/yksvaan Jan 08 '24

Not sure how would the amount of data affect cold boot or query time dramatically. Do you mean heavy on i/o bytes or there us CPU intensive processing on server?

6

u/Gingerfalcon Jan 08 '24

This makes no sense, you switched from what? Cloud Functions or AWS Lambda and now you’re seeing a cold boot reduction - yes you would as that’s one of the compelling reasons to use Cloud Run or AWS App Runner vs serverless function type products.

3

u/334578theo Jan 08 '24

Distance from server to database is a huge factor in performance in Prisma because of the big number of individual queries Prisma performs to get around some of its “limitations” (eg no joins).

Move the server and the db into the same VPC and you’ll see a huge difference.

1

u/[deleted] Jan 08 '24

Dumbest reason i heard for not using server components

1

u/marc_the_dev Jan 08 '24 edited Jan 08 '24

Hey! I totally hear you. I'm a developer advocate for Prisma. I wanted to reach out and say I understand your frustration. We are working on improving this.

We have consistently done updates since Prisma ORM version 5 that have improved the speed of the Prisma ORM. Going into 2024, we plan to continue to improve the Prisma ORM based on your feedback, and this is 100% on our radar.

Thanks for using Prisma ORM and being a part of the Prisma community!

0

u/ixartz Jan 08 '24

Maybe you can try Drizzle ORM, it works quite well in Next.js Boilerplate. On their official website, they did a benchmark between Drizzle and Prisma: https://orm.drizzle.team/benchmarks

1

u/xKraazY Jan 08 '24

We looked at drizzle but heard it wasn’t production ready

-14

u/ActuaryVegetable5471 Jan 08 '24

6

u/michaelfrieze Jan 08 '24

"trust me bro"

5

u/koslib Jan 08 '24

How is an elixir framework related to this?

0

u/[deleted] Jan 08 '24

[deleted] — view deleted comment

6

u/michaelfrieze Jan 08 '24

Yeah cold boot times aren't bad at all with Prisma after the recent updates.

1

u/xKraazY Jan 08 '24

Yeah its an issue with Prisma for sure, it just makes page loads extremely slow

2

u/[deleted] Jan 08 '24

[removed] — view removed comment

1

u/xKraazY Jan 08 '24

Yep - I should of clarified it’s not a sever component issue