WebSocket workflow for serverless with T3 stack
I'm just starting with WebSockets, and would like to get confirmation if I'm on the right track regarding how the communication between services is made. The basic pitch for the part of the project I want to discuss is the following: 2 users send information to the server. The information is only processed when both of them deliver their data, and then is sent back via a WebSocket subscription for both of them. Also, in order to process this new information to send to them, I need not only the data sent from both the users, but the previous processed information as well (this, I believe, means I'll need to store this processed information somewhere that is quickly retrievable so I can get it back in the next round of requests).
The workflow I had in mind is like this:
- User 1 makes a POST request for Next.js with the desired data
- Next.js gets Redis' data to confirm if User 1 is the last to post in this round
- Since it's not, Redis' data is updated to include User 1's data in this Round
- This triggers the Pusher subscription to send to the Client the list of users who sent and who still did not send the data
- User 2 makes a POST request for Next.js with the desired data
- Next.js gets Redis' data to confirm if User 2 is the last to post in this round
- Since it is, we get Redis' data of the previous processed information
- A function is executed to create a new processed information (it takes both users's data and the previous processed information, all which we got from Redis and the User 2 POST request)
- This new processed information is stored in Redis alongside the User 2's data, so we have both their data and the processed information that was a result of it
- Both the Processed information and the list of users who sent and who still did not send the data are sent to the Client via Pusher's subscription
- Client reads and shows this processed information and a new round is initiated
Is this the right workflow with serverless? Is it wrong? Overkill?
5 Replies
the main issue is serverless is hard with ws
as you have to keep the connection open
Yes, they seem like contradictory concepts
But in this case, at least from what I gathered, Pusher is not serverless, is it? The conection/subscription between Pusher and the client is a breeze to make, and for the Next.js backend part, I can access Pusher's server trough it to modify it data that's then delivered to all subscribers
It's like a serverless function contacting a serverful websocket service to change info
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
this
lambdas in theory should run and be deleted (cold starts xD)
ws you wanna keep the connection between server/client
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View