How do tRPC WebSockets work with NextJS

Hey! I've recently stumbled upon this repo: https://github.com/trpc/examples-next-prisma-websockets-starter. I'm a little confused on how it would be able to hold a connection with a serverless environment.
Solution:
it looks like they setup a websocket server there, and host they on "render"
Jump to solution
12 Replies
Solution
Zion
Zion10mo ago
it looks like they setup a websocket server there, and host they on "render"
petdomaa100
petdomaa10010mo ago
So the site and websocket server are hosted differently? Or everything is hosten on render?
Zion
Zion10mo ago
pretty sure everything is hosted on render try to deploy that exmaple app yourself on render to see how it works ig
Neto
Neto10mo ago
on the example there are 2 servers running on the same machine
Neto
Neto10mo ago
GitHub
examples-next-prisma-websockets-starter/package.json at main · trpc...
🏓 tRPC Next.js WebSocket Starter. Contribute to trpc/examples-next-prisma-websockets-starter development by creating an account on GitHub.
Neto
Neto10mo ago
in the real world, you are going to use something like pusher, socketi or whatever
Zion
Zion10mo ago
why is it preferable? trpc subscriptions are not production ready or?
Neto
Neto10mo ago
trpc is fine the ws side is the faulty one vercel does not host any ws service vercel run on lambdas, so you wont host there as well in the example is fine to host both of them, but in the real world you wont gonna use the same
Zion
Zion10mo ago
its not possible to host the ws server on render or something and the lambdas / app itself on vercel?
Neto
Neto10mo ago
yep, its a alternative
darthreza
darthreza10mo ago
Question from a beginner, if we are running a linux bare metal server that we have configured to be able to run next.js apps, then it should be fine to use ws, right? The reason not to use ws is not that the ws package is inherently limited, but that some hosting platforms to not allow it. Correct?
OtterSwims996
OtterSwims9965mo ago
Yes i think you're totally fine running something like this on your own linux server