Implementing Real-Time UI Updates with SSE/WebSockets for Twilio SMS Responses in Next.js
Unanswered
Tufted Flycatcher posted this in #help-forum
Tufted FlycatcherOP
Hi everyone! I'm working on a Next.js application that needs to display real-time updates in the UI. The updates are triggered by incoming SMS messages from vendors, processed through Twilio's webhook, which then updates our MongoDB database.
Here’s the flow:
Vendor sends an SMS reply.
Twilio webhook receives the message.
My API route (/api/incoming-sms) handles the incoming message and updates MongoDB.
The Challenge:
I need the UI to reflect these updates in real-time so that our business users can see the responses as they come in, without having to refresh the page. They typically have this page open for 7-8 hours a day.
Current Setup:
I have the webhook and database update mechanism working fine.
For the real-time UI, I'm considering Server-Sent Events (SSE) or WebSockets, but I need to maintain the connection reliably open for the entire business day. How would you go about doing this? Would a serverless architecture be okay?
Here’s the flow:
Vendor sends an SMS reply.
Twilio webhook receives the message.
My API route (/api/incoming-sms) handles the incoming message and updates MongoDB.
The Challenge:
I need the UI to reflect these updates in real-time so that our business users can see the responses as they come in, without having to refresh the page. They typically have this page open for 7-8 hours a day.
Current Setup:
I have the webhook and database update mechanism working fine.
For the real-time UI, I'm considering Server-Sent Events (SSE) or WebSockets, but I need to maintain the connection reliably open for the entire business day. How would you go about doing this? Would a serverless architecture be okay?
1 Reply
Serverless is not a good fit for long lived connections. You'll need to deploy a websocket or SSE server separately and connect to it in a client component. Something like SocketIO will auto reconnect and has good logic for fallbacks etc...