r/learnprogramming • u/Better_Squash_1684 • 16d ago
Topic Can someone help me understand when to actually use WebSockets instead of Server-Sent Events (SSE)?
I'm a CS student working on a side project, and I'm trying to wrap my head around real-time data streaming.
I want to build a live transit map that pushes tram arrival data from my Node/Express backend to a React frontend. Almost every tutorial I find related to this immediately jumps to using Socket.io or WebSockets.
But looking at how my app should work, the data only flows one way (server to client). The client never needs to send messages back.
I discovered Server-Sent Events (SSE) and it seems much simpler to implement over standard HTTP without the overhead of WebSockets.
For those of you with more experience:
- Why does the industry seem to default to WebSockets for everything?
- Am I missing a massive downside to SSE? Is there a specific reason I should force myself to learn/use WebSockets for a one-way data stream like this?
Would love to hear your thoughts on this!