Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
2 replies
O2K

tRPC queries&mutations really slow on Vercel+Planetscale deployment

Hello!
I deployed my T3 app to vercel and the DB to Planetscale, and I am seeing some incredibly slow speeds on the queries/mutations for tRPC. Take this mutation for following a user for example:
follow: authedProcedure
    .input(
      z.object({
        id: z.string(),
      })
    )
    .mutation(async ({ ctx, input }) => {
      const userId = ctx.session.user?.id;
      if (!userId) throw new TRPCError({ code: 'UNAUTHORIZED' });
      const user = await ctx.prisma.user.findUniqueOrThrow({ where: { id: input.id } });
      const userFollow = await ctx.prisma.userFollow.upsert({
        where: { followerUserId_followTargetUserId: { followerUserId: userId, followTargetUserId: user.id } },
        create: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
        update: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
      });
      return {
        userFollow,
      };
    }),

This mutation averages around 800-1000 ms on Vercel+Planetscale, while it locally never takes more than 100ms. I would love some insight into what I might need to look into. Maybe something is misconfigured? Both Planetscale and Vercel are located in same region (eu-west).

This problem is for all tRPC queries/mutations 😬

Thank you for reading
unknown.png
Was this page helpful?