T3 for a chat app
Although I don't remember the exact video now. I remember Theo saying that the t3 stack would not be optimal for an application that constantly updates it's data. I assumed this meant something like a chat app that relies heavily on web sockets. If I am correct here, could someone help me understand why using t3 app is not optimal for this type of app? Also what should I use instead?
11 Replies
i think this is the video you're talking about - https://youtu.be/-R9uHm0G5m4
T3 stack is expected to be deployed on a serverless environment. Serverless isn't designed for long connections, so you can't really use websockets
You can still use T3 for a chat app. tRPC has subscriptions, and they are very useful for getting updates. Just deploy it with docker on a VPS
Just deploy it with docker on a VPS
wouldn't you be deploying all of your next.js
app on your own this way? is there any disadvantages between this approach vs deploying on vercel?vercel run on lambdas
and you (kinda) can't use ws on lambdas
You can take a look at this example that uses
soketi
for sockets that might help you.
https://github.com/pingdotgg/zapdosGitHub
GitHub - pingdotgg/zapdos
Contribute to pingdotgg/zapdos development by creating an account on GitHub.
This Vercel article provides some solutions to the issue with websockets
https://vercel.com/guides/publish-and-subscribe-to-realtime-data-on-vercel
I am planning to use Supabase Realtime to subscribe the frontend/client to Supabase so that changes made to the database can be published back on the client
Vercel Documentation
How to Add Realtime Communication on Vercel Applications
Learn how to integrate realtime communication to your Vercel application using providers like Ably or Supabase.
Hmm, looks like there are 2 ways: drop idea of building chat (build it as http / use 3-rd party embedded solution) or leave Vercel (welcome to the Docker world and getting lots of devops job)
Hmm, maybe server-side events can be somehow used for this purposes?
Server sent events have the same problems that web sockets do in regards to deploying on serverless I believe
Nextjs doesn't force you into deploying on serverless, so you could always just put it on some random VPS if you don't expect to be the next whatsapp
Hmm, and what about building separate ws server in NodeJS, hosting it somewhere, and connecting to it from NextJS client (from component)?
I really do not want to leave Vercel, as deploying create-t3-turbo somewhere is a f..ken hell
Yeah that seems like it could be a good way to go about it, that's pretty much what all those other web socket providers are doing
Interesting thing is how to make that ws connection protected, as it is external app.
supabase may be the best solution. I added real time post update to my simple app using
postgres_changes
(https://supabase.com/docs/guides/realtime/extensions/postgres-changes) https://github.com/adnanjpg/baykus/blob/main/src/hooks/useRealtimePostUpdates.ts
for chat, the Broadcast
method would probably be better https://supabase.com/docs/guides/realtime/extensions/broadcastPostgres Changes | Supabase Docs
Getting started with Realtime's Postgres Changes feature
GitHub
baykus/useRealtimePostUpdates.ts at main · adnanjpg/baykus
Contribute to adnanjpg/baykus development by creating an account on GitHub.
Broadcast | Supabase Docs
Getting started with Realtime's Broadcast feature