Using ManagedRuntime in Next.js with TRPC and Database Connections in Serverless Environment
I have a nextJS app which exposes a TRPC router & of course the webpages themselves.
I just want to clarify whether I am using ManagedRuntime’s correctly.
Would I be correct in initialising my runtime inside my NextJs middleware & attaching this to the “request” so that all TRPC routers & nextjs pages can access the runtime?
The benefit I see here is that we’ll only have 1 single runtime per request.
I have a few other questions:
- are there any tips/tricks I should implement to my nextJS requests, perhaps attaching the user to the ru time via a layer?
- given that NextJS is hosted in a serverless environment, should I be worried about the number of connections that my database is receiving? On all valid nextjs requests that require the runtime & do DB queries, my SqlClient will make a connection to my Postgres instance. Generally in the past I’ve not used serverless and done pooling.
- is there anything specific I should think about that maybe I haven’t yet?
I just want to clarify whether I am using ManagedRuntime’s correctly.
Would I be correct in initialising my runtime inside my NextJs middleware & attaching this to the “request” so that all TRPC routers & nextjs pages can access the runtime?
The benefit I see here is that we’ll only have 1 single runtime per request.
I have a few other questions:
- are there any tips/tricks I should implement to my nextJS requests, perhaps attaching the user to the ru time via a layer?
- given that NextJS is hosted in a serverless environment, should I be worried about the number of connections that my database is receiving? On all valid nextjs requests that require the runtime & do DB queries, my SqlClient will make a connection to my Postgres instance. Generally in the past I’ve not used serverless and done pooling.
- is there anything specific I should think about that maybe I haven’t yet?
