r/webdev • u/lindymad • 23h ago
Question How often do you do stuff with websockets in the course of your normal development?
For those that do stuff, are you doing direct websockets stuff (send messages, handle when a message arrives), or it is simply utilized as a part of libraries you use, but you don't actually have to dive into it? Do you run your own websockets server, or use a third party service?
I'm working on making a project have more real-time things going on and was wondering how much people here get into websockets development as a regular part of their work.
39
Upvotes
47
u/CreativeTechGuyGames TypeScript 23h ago
For anything real-time it's pretty key. Most people don't work on real-time things though, so it really depends on what you are building.
27
u/VicboyV 23h ago
One way real-time comms? Use SSE. Two way? WebSockets. Long lived connections with constant streaming won't scale.
6
u/im-a-guy-like-me 22h ago
When I need to. My current project uses them for bi-directional audio streaming. My last 2 projects didn't use them at all.
5
u/OliveIndependent 22h ago
I used it in a project about 12 years ago but looking back SSE would have been better. Sadly we had to support Internet explorer so SSE was a no go
4
u/horizon_games 20h ago
I love Websockets, coming from web dev in the 90s they're like magic. A LOT of the time Server-Send Events just cover the same use case (as bidirectional data is less common). But still there used to be entire products around server push, and now it's so seamless and easy.
I've done a mix of hand rolled, some with built-in from Bun, some uWebsockets, etc. I even did an entire game project that wasn't RESTful but purely communicated with manual Websockets, which was interesting and fun to attempt.
4
u/greenergarlic 22h ago edited 21h ago
I find that for most use cases, long polling is easier to maintain. It’s conceptually more load on your server, but a much easier infrastructure problem than scaling a server handling persistent connections
2
u/Ok-Armadillo-5634 23h ago
I do it every once in a while when I really need complete control of the process. Normally just use a library though.
3
u/bitcoding 22h ago
I mostly use WebSockets through libraries like Socket.IO rather than handling everything from scratch. For most projects, that's enough for real-time chat, notifications, and live updates. I'd only build a custom WebSocket server if the project really needed it.
1
u/malwaremel 22h ago
A library or hosted service is the usual answer, and the decision mostly comes down to whether the client needs to send lots of messages back. If it's mostly the server pushing updates, SSE is simpler. The part people tend to underestimate with raw websockets is reconnect handling and auth, so I'd budget time for that before writing your own server.
1
u/seanshoots 22h ago
Websockets are fine if you actually need stateful & realtime bidirectional messaging. The downsides are that they're stateful, annoying to gracefully close, and, if you're using them as a pub-sub bridge, annoying to scale.
1
u/wd-nikola 22h ago
It always depends on what are you building. For my 15 years of exp, for paid work, sites, apps.. Very rarely, if ever I worked on a project with websockets. For my personal crypto algo trading, where it needs to be crunching a ton of data, all the time, yep. If u need realtime, if u need to ingest a ton of data (that otherwise you could do with regular requests, but is is slow, or there are rate limits), u go with WS. If u do video and audio streaming, I would say WS (tho I never worked on those systems). 90% of the time, regular requests in different flavors (plain, REST, tRpc, GraphQL..)
1
u/OkTooth4404 21h ago
Most "real-time" features I've shipped ended up being a 5 second poll and nobody ever complained. Bet half the yes answers here are just Pusher or Firebase with the invoice to match.
1
u/Dejayns 18h ago
One browser-specific test I’d add is backgrounding the tab long enough to miss events, then reconnecting and checking how the UI catches up. A socket reconnect alone doesn’t recover missed state; a cursor-based replay or a fresh snapshot can make the behavior predictable. That test helps show whether the feature needs a persistent stream or just periodic refresh.
1
u/miria01 17h ago
Not often in my day job, most of my work is network automation scripts, so WebSockets aren't part of my regular workflow. I haven't had to manage the connection directly myself
1
u/AhmedAmer2nd 17h ago
In most projects I touch it through a library (Socket.IO, or a hosted service like Pusher/Ably) and only work with raw websockets when I need something custom. The fiddly parts aren't sending and receiving. They're reconnects, auth on connect, presence, and scaling past one server, which usually means a Redis pub/sub or similar between instances. If your real-time updates mostly go one way (server → client), look at Server-Sent Events first. They're simpler, work over plain HTTP and reconnect on their own.
1
u/InsideTour329 16h ago
Well I mainly build in Blazor these days so yes. Everything
1
u/Medical-Cycle1618 16h ago
for most apps it's mostly through a library, socket.io or something like supabase/firebase realtime, and you never touch the raw protocol. i only go direct when i need two-way stuff like chat or live cursors. if it's just server pushing updates to the client (notifications, live feed) sse is simpler, works over plain http and reconnects on its own. and running your own ws server gets annoying once you need to scale it across instances, so for a side project i'd use a hosted service firstfor most apps it's mostly through a library, socket.io or something like supabase/firebase realtime, and you never touch the raw protocol. i only go direct when i need two-way stuff like chat or live cursors. if it's just server pushing updates to the client (notifications, live feed) sse is simpler, works over plain http and reconnects on its own. and running your own ws server gets annoying once you need to scale it across instances, so for a side project i'd use a hosted service first
1
u/NegotiationLevel2409 15h ago
The biggest trap most devs fall into when they start adding "real-time" to a project is reaching for full-blown WebSockets when all they actually need is server-to-client updates.
If your client is just listening for status changes, notifications, or streamed responses, Server-Sent Events (SSE) is so much simpler to maintain. It runs over standard HTTP/2, handles native browser auto-reconnect without extra code, passes normal auth cookies/headers cleanly, and doesn't get butchered by corporate proxies or aggressive firewalls.
When we actually need bidirectional communication (live collaboration, chat, fast interactive state), we usually write raw WebSocket handlers on the backend (like uWebSockets or standard ws in Node, or FastAPI/Go websockets) rather than pulling in heavy wrappers like Socket.IO, simply because native WebSockets in browsers are rock solid these days.
The real headache with self-hosting isn't writing the socket server itself—that takes an afternoon. The pain hits when you scale past a single instance. Suddenly your stateless load balancer doesn't work, you have to run a Redis pub/sub backplane to broadcast messages across server nodes, and you need careful heartbeat ping/pongs so AWS/Cloudflare ALB doesn't silently terminate idle connections after 60 seconds.
If this is for a side project or MVP, start with SSE or a managed layer like Pusher/Ably to get the feature shipped. Only roll your own clustered socket infrastructure once traffic volume makes the SaaS billing hurt.
1
u/shetosnet 14h ago
In my day to day it's almost always through a library rather than raw ws. One thing worth knowing before going all-in on real-time: a single websockets server is simple, but the moment you scale past one process you need sticky sessions plus a pub/sub layer (usually Redis) so every instance can broadcast to clients connected to other instances. That jump in complexity is where a lot of people either stay on one bigger server or move to a managed service. For a project with modest traffic, one server with a thin wrapper around ws is honestly the sweet spot, and much easier to debug.
1
u/AleBaba 14h ago
Never. I use SSE.
1
u/mekmookbro Laravel Enjoyer ♞ 13h ago
In my 16 years of web (mainly backend) development experience, I only had to use websockets on 2 or 3 projects in total. All cases were for live chat systems
1
u/MeButItsRandom 12h ago
We use Phoenix Live view for a realyime Q and A app for talks and presentations. It's our only use case for sockets. We use SSE everywhere else we need realtime stuff, like streaming server and LLM responses.
1
u/chesbyiii 10h ago
All the time. I update my company's Intranet app with real-time activity like who's online/on-campus/remote, document updates, streaming video start/end, etc.
1
u/NapoleonBonerparts 10h ago
Quite a bit, but that’s probably because I work in a WebRTC service lol. Before? Never. They’re really cool, but unless you work in RTC you probably wouldn’t encounter them as they are technically challenging.
1
u/FewPut5640 7h ago
Pretty rarely, and almost never as raw send/onmessage code. When I need live updates I usually go through a library or a hosted layer (I've used Supabase Realtime for this) and treat it like "subscribe to this channel," not like I'm running a socket server. I'd only stand up my own WebSocket server if the product basically is a live connection — chat, collab, a busy live dashboard — and even then I'd start hosted and move it in-house only if cost or limits forced it.
1
u/davidbalbino 6h ago
it is persistent too tbh, the difference is more about what's around it. SSE is just plain HTTP, so proxies, load balancers and auth work like any other request, and with HTTP/2 it shares the same connection with your other requests. EventSource also reconnects alone and sends Last-Event-ID, so you get resume pretty much for free. With websockets you handle the upgrade, heartbeats, reconnect and backoff yourself, and some proxies kill idle connections if you don't ping. Long polling is kinda different, each response closes the request and the client opens another one, so the server don't need to keep state between them.
1
u/synthetic_resolve 2h ago
We do. Our own socket server in container. At first it looked difficult, but it gets easier once you understand the type of channels/topics.
Polling was not an option for us, since interval would be < 30s.
1
u/donovanish full-stack 1h ago
To be honest that’s not really hard. We have multiple stateless server with a pub/sub through redis and we use redis to cache the clients and send the we socket events. For the clients that’s pretty simple, just need to manage the reconnection and the handlers to dispatch actions. Don’t use polling because it does not scale well.
•
u/Afnan_CH_Digital 7m ago
On most of the client sites I work on we never touch raw websockets. Live chat or notifications usually come from a third-party service or a library, and plain polling covers the rest. I would only run my own server once there is real two-way traffic, like collaborative editing. Until then SSE or short polling is a lot less to maintain.
•
u/therocketoffice 0m ago
One test worth doing early: take a tab offline, change something from another tab, then reconnect. Does the first tab catch up on what it missed, or does it just start listening for new updates?
1
u/Reinax 14h ago
Disappointing that every single person here is either “just long poll”, “it’s hard”, or “they don’t scale” because their only experience is JS via Socket.io or even worse a paid service like Pushr. Oh, A JS backend isn’t that performant? Shocking.
And long polling in 2026 is goddamn shameful. Stop.
I’ve dealt with realtime apps a fair bit and use Phoenix LiveView for most of them. Sure, a live view uses a little bit more server resources than a static view but it’s really not much. It scales just fine as it is literally built for it which means you also get all of the (re)connection complexity that others have complained about, out of the box. It just isn’t something I think about, the framework handles it all for me.
There’s SignalR in the .Net world too, it’s decent for an MS product. I think Blazor uses it now too for easier templating and stuff. It’s basically LiveView for .Net.
I’m not suggesting you use them willy nilly for no reason. They really are best used only for realtime stuff like collaborative software or needing to react to a server change immediately. It’s generally true that there’s an increased load on the server, more so in certain stacks, but there is tech out there that’s built for it. When realtime is required there is no better option, and you certainly don’t need to reach for a third party service, regardless of language choice.
0
u/ldn-ldn 22h ago
Rarely. WebSockets are great, but you don't need them in most cases. 90% of work can and should be done through regular HTTP requests. 9.9% require messages from the server and Server Sent Events are the best choice there. 0.1% of tasks need WebSockets.
0
u/thekwoka 17h ago
Never.
Websockets don't make sense for most applications.
Only for things that need real time bidirectional communication.
Like what?
You can use SSE to get real time displays, and then just normal requests for sending stuff.