Cold Boot Optimizations

I have a next.js app that uses trcp for all of the routes. I am noticing cold boots are slow. It is likely I am doing something wrong, or is there an optimization to be made? I also want to understand how next.js creates the underlying lambda functions with trcp. Is each router its lambda or something else? 
This is a mono repo I have a services package containing all of the service functions and unit tests. I then have an api package that wraps functions from the service package inside routers. The service package contains classes, for example, userService, notificationsService, and more. Each of these classes takes in a configuration. Almost everyone takes in a database connection, but some take in secrets to interact with external APIs. I have a factory that instantiates all of the classes, takes in every secret, and returns an instance of the services. Example: 
return {
 user: new UserService(databaseURL) notification: new NotificationService(SendridKey, databaseURL), moreServices… } I pass this in the context of trcp and interact with the service I want inside of each router. Example: likeThread: protectedProcedure .input( z.object({ tweetId: z.string(), }), ) .mutation(async ({ ctx, input }) => { const { serviceInternals, session } = ctx; await serviceInternals.user.toggleLike( session.user.walletAddress, input.tweetId, ); }), subscribeToEmailList: protectedProcedure .input( z.object({ email: z.string().email(), }), ) .mutation(async ({ ctx, input }) => { const { serviceInternals } = ctx; await; }),

 I need to be able to perform unit test on each of the service functions individually (client requires % unit code coverage), and I like having the service layer detached from the router. 

On cold boot, this takes 5-10 seconds to load. After that, it is 1 second.
Alex / KATT 🐱195d ago
splitting up the endpoint is usually the way
Alex / KATT 🐱195d ago
trpc/examples/soa at main · trpc/trpc
🧙‍♀️ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - trpc/trpc
sudoSolidity195d ago
Wow, I had no idea you could do this super cool. Do you know how next works with the trcp? Does it make new functions for the data in the route, or is each router treated as a function? I'm checking now how much code I am using on boot and if it's all in the same service. I don't think I need to have multiple endpoints. Maybe it would be better to no use a class and instead, just bunch functions together and import them into the router?
Alex / KATT 🐱194d ago
Each router as a function Your cold starts can also be related to prisma, so look up what you can do there too
More Posts
Cancel useQueries with single functionis there a way to abort useQueries with function call (e.g. cancel, abort)?There is a logger middleware like morgan for express?There is a package with a nice logger middleware? ThanksImplementing wsLink causes issues on ReactI get an error within the console stating ``` Uncaught (in promise) TypeError: Cannot read propertieUnderstanding how too reuse TRPC with React Server ComponentsHopefully I am understanding this correctly, but I have created a `experimental_createTRPCNextAppDirWhat would be considered best practice for getting data and invalidating queries?I have a really simple task management app (doing it to learn stuff). Tasks are grouped in projects Calls to specific table not working in production, fine locallyI am having a strange issue since yesterday. I am using nextjs TRPC and Prisma to connect to a planeanyone else getting a failed to fetch in latest next versionsnot sure if this is happening to more people, I tried literally everything, changing to 127.0.01, upMissing keys in TRPCError when returning as JSONHey all! I am returning a TRPCError from a custom TRPC server but only the code and name keys seems How to close a Standalone adapter server?I want to run some integration tests with Vitest and for some reason I don't want to use the `createtRPC Client within Next.js but with external standalone server?Hi, I have an old Next.js project that used tRPC and we're currently in the process of separating oReview of inner and outer context with expressHello, I didn't find any example that uses inner (for testing) and outer context with express. ThatShould i use lint rule explicit-function-return-type when use trpc?I got warning for this lint When how to delete next-auth modules from trpc stacjas the title saysWrapper Component: Unable to retrieve application context.Hello tRPC-Community, I have ran into a funny "issue" while gaining my first experiences with tRPC.