SGeri
TTCTheo's Typesafe Cult
•Created by SGeri on 4/21/2023 in #questions
Serverless (Vercel) Prisma Cold Start Optimizations
Prisma's performance in serverless environment is a hot topic currently and I made this topic to collect best practices, optimizations and tips to use prisma's extremely great developer experience with vercel's blazingly fast serverless functions.
As I've previously seen it, cold start are around 2 seconds, while warm requests are handled in ~600ms in a very simple scenario.
I understand, high traffic sites don't face this issue as much as others, since they keep functions warm.
Switching to (or using them parallel) kysely or drizzle is not really an solution imho.
Going back to container based deployment is currently my go-to option if performance matters this much, but having leave Vercel's awesome features behind is a real pain.
I'd be happy to see your solutions & optimizations for this problem. thanks!
30 replies
TTCTheo's Typesafe Cult
•Created by SGeri on 4/16/2023 in #questions
TRPC + Prisma Caching
Hey. I'm using trpc middlewares to inject the authenticated user (from the db using prisma) to the procedure's context. each request makes at least one DB query and thats expensive. i already have a redis database for other reasons and I'd like to introduce caching of users. the point is that the application is heavily dependent on the user so it is not acceptable to get outdated.
my idea was to use redis with the key of the userid and the value is the the user data. when there is an entry in the cache, we use that instead of the using the db. on any kind of user update, we remove the that users entry from the redis db.
what do you think about this approach/strategy?
7 replies
TTCTheo's Typesafe Cult
•Created by SGeri on 3/18/2023 in #questions
Clerk shared user state
I'm using the t3-turbo-and-clerk template and as I see, TRPC initializes the context with clerk's getAuth method so that the auth info can be access from the procedures.
getAuth makes it possible to create a TRPC middleware so that the (whole) user returned from the db (relation with clerk's userId) can be accessed in the context.
but what are the best practises to get the full user (from the db, not just from clerk) in the frontend? does clerk provide a simple way for that? if not, what is the best way to have the user also on the client side? I'm thinking about something just like the useUser hook from clerk but with my custom data
5 replies
TTCTheo's Typesafe Cult
•Created by SGeri on 3/11/2023 in #questions
createTRPCNext returns strings, cannot use .withTRPC()
16 replies