r/webdev • u/lindymad • 5d 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.
73
Upvotes
63
u/CreativeTechGuyGames TypeScript 5d 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.
41
u/VicboyV 5d ago
One way real-time comms? Use SSE. Two way? WebSockets. Long lived connections with constant streaming won't scale.
7
u/im-a-guy-like-me 5d 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 5d 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
5
u/horizon_games 4d 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.
5
u/greenergarlic 5d ago edited 4d 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 5d ago
I do it every once in a while when I really need complete control of the process. Normally just use a library though.
2
u/NegotiationLevel2409 4d 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.
2
u/shetosnet 4d 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.
2
u/mekmookbro Laravel Enjoyer ♞ 4d 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
2
u/Hostman_com 3d ago
One detail to check when choosing a library or hosted service is how it handles permission changes on an open connection. In a test environment, subscribe a user to a private channel, revoke their access from another session, then publish a new event.
Check that the existing connection stops receiving that channel's events and that reconnecting doesn't restore access. That gives you a concrete check of what the library handles and what authorization logic your app still needs.
2
u/nn_gyunx 3d ago
Most of our realtime goes through a library, but we do run the socket server ourselves, one process per API instance with Redis pub/sub behind it so a message published on one instance still reaches clients connected to the others. The fan-out was the easy half. What actually took time was the reconnect: phone browsers drop the connection when the tab goes to the background, so when the client comes back it asks for everything since the last event id it saw, and the server answers from a small outbox table instead of pretending the socket never dropped.
The other thing I would say up front is to treat the socket as a notification channel, not as the place where state lives. Every event we push points at a row that already exists and the client refetches when it is unsure, which has saved us more than once when a deploy restarted the socket workers mid-session.
What kind of realtime is it? Live cursors or chat need a real two way socket, but if it is mostly "this thing changed, refresh it", SSE over plain HTTP with normal POSTs for sending is far less to operate and it reconnects on its own.
2
u/boer0327 3d ago
honestly rarely touch raw websockets anymore. for most live updates or LLM streams we just use SSE over plain HTTP and normal POST requests back.
1
u/seanshoots 5d 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 5d 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 4d 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 4d 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 4d 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 4d 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 4d ago
Well I mainly build in Blazor these days so yes. Everything
1
u/AleBaba 4d ago
Never. I use SSE.
1
u/MeButItsRandom 4d 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 4d 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 4d 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 4d 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 4d 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 4d 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 4d 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.
1
u/Afnan_CH_Digital 4d 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.
1
u/therocketoffice 4d 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/Last_Pay8887 3d ago
Not super often day-to-day, mostly for chat, live dashboards, or collaborative stuff
1
u/MidiSentence 3d ago
I’ve gone down the rabbit hole designing and implementing my own. I’ll use whatever libraries are standard in production though unless I have a reason to. It’s fun to learn and work with and not too complicated. It’s just the others are battle tested by thousands of devs. Unless it’s something really custom that needs to be done I don’t think it’s worth the time except to learn how it works on a deeper level.
1
u/yami_odymel 3d ago
I was a socket lover, but not anymore. Unless you really need low-latency, bidirectional communication, things like notifications or chat can just use regular HTTP requests or SSE.
Long-lived connections add complexity to scaling, recovery, and load balancing.
1
u/Ronin-s_Spirit 3d ago edited 3d ago
I wrote a web server using Nodejs modules, naturally I have to handle HTTP coming in and out. While not technically manually managing sockets, I still have to manage streaming (single file streams, composite streams, interleaved streams) and deal with underlying bullshit (like TCP dying as soon as I reply with a 400 or 500).
I prefer long polling when I can get away with it (i.e. being a proxy to another server's api).
If you're looking for something faster you should try SSE or webhooks.
1
u/Ok-Snow-6553 3d ago
Honestly, I barely touch them directly anymore. Unless I'm building something like a live chat, I just use SSE (Server-Sent Events) or fall back to polling.
Running your own WebSocket server with sticky sessions is just too much of a headache for simple real-time updates.
1
u/LittleThingsStudio 3d ago
I've used WebSockets in several projects, mainly for real-time chat, candlestick charts on trading platforms, and other frequently changing trading data. For features that don't require immediate updates, regular polling is often enough.
As for building your own service or using a third-party one, I think it depends on team resources, data privacy requirements, and how much customization you need.
Take IM systems, for example. A third-party service is usually enough for basic messaging. If you need extensive customization or strict control over your data, building your own may make more sense.
But building a complete IM system takes a lot of development effort. A simple WebSocket service is one thing; a full messaging system is another.
1
u/vdmeijer 1d ago
Depending on the application you are writing for. But I use them quite a lot.
1
u/Effective_Occasion77 55m ago
Websockets is it's own protocol not related to other RFCs. What exact problem are you having?
1
u/Reinax 4d 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 5d 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 4d 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.
2
u/[deleted] 5d ago
[removed] — view removed comment