r/webdev • • 1d 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.

49 Upvotes

69 comments sorted by

50

u/CreativeTechGuyGames TypeScript 1d 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.

4

u/Economy-Resort-9532 1d ago

Most of the time it's hidden behind a library like socket.io or SignalR. I only really have to poke at the raw frames when something goes weird, which isn't often. Running your own server isn't too bad with a small user base, but once you need to scale past sticky sessions it becomes a whole thing.

7

u/CreativeTechGuyGames TypeScript 1d ago

I don't like being bound to a specific protocol like that. It really limits you for not much benefit.

And you can have serverless infinitely scalable WebSockets with AWS API Gateway with AWS Lambda so you can have clients with persistent two-way connections without needing to worry about the long lived connections server side.

28

u/VicboyV 1d ago

One way real-time comms? Use SSE. Two way? WebSockets. Long lived connections with constant streaming won't scale.

16

u/thekwoka 21h ago

And to be clear, the two way should be lots of two way, not just technically two way.

A chat app will work great with SSE for the messages coming in, and normal requests for sending messages.

A Game or something would be more where websockets are in the realm of the right choice.

4

u/Lichcrow 18h ago

I found this by bugging my frontend with repeated connection attempts with websockets. Migrated to sse the following week

6

u/im-a-guy-like-me 1d 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 1d 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 1d 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 1d ago edited 1d 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

4

u/SimpleWarthog node 22h ago

it is, to a point

years ago we had an in-house CRM system that used long polling, and as features increased, and so did the number of users, everything was grinding to a halt

we swapped it all out with websockets using socket.io and the difference was actually insane

you're right tho, no need to Iver engineer something at start

0

u/thekwoka 21h ago

Why choose websockets over SSE?

3

u/SimpleWarthog node 21h ago

this was like 15 years ago lol, SSE wasn't as prevalent

also there was some bi-directional stuff

1

u/thekwoka 21h ago

or just SSE

1

u/greenergarlic 11h ago

SSE has the same issue as websockets: you need a persistent connection to the server as long as the user is on the site. That’s complicated to manage during deploys or scale outs

1

u/renevaessen 20h ago

How is long-polling or SSE not maintaining a persistent connection?

2

u/greenergarlic 16h ago

When polling, each request is stateless. So it doesn’t matter if the underlying server changes.

SSE requires a persistent connection, though, same as websockets

2

u/Ok-Armadillo-5634 1d 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 1d 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.

3

u/thekwoka 21h ago

None of those things you listed even benefit from web sockets over just SSE...

1

u/malwaremel 1d 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 1d 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 1d 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 1d 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 22h 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 22h 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 21h 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 21h ago

Well I mainly build in Blazor these days so yes. Everything

1

u/Medical-Cycle1618 21h 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 19h 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 19h 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 18h ago

Never. I use SSE.

1

u/mekmookbro Laravel Enjoyer ♞ 17h 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 16h 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 14h 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 14h 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 12h 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 11h 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 6h 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 6h 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 4h 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 4h 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/Open-Adhesiveness-86 3h ago

Own server, directly, a couple of times a year. One thing to know before swapping to SSE like everyone's suggesting: on HTTP/1.1 browsers cap you at ~6 connections per origin, so a user with five tabs open starves the rest of your requests. HTTP/2 multiplexes so it's fine, but then you need h2 all the way to the app. And whatever you pick, check your proxy's idle read timeout, nginx defaults to 60s and will quietly drop a websocket with no traffic unless you're sending pings.

1

u/IllImagination9652 59m ago

Most of the time I don't hand-roll the protocol. For product features I want the library or the platform's socket layer, and I only drop to raw send/onmessage when I have to. I have run my own websocket server when the connection was the product (live chat), because reconnection, auth, and "what happened while they were gone" end up being yours anyway. A third-party socket service doesn't remove that. Third-party is fine for presence or low-stakes updates. If you're adding more realtime to an existing app, don't put business state only in the socket. Persist it, and let the socket notify that something changed.

1

u/Last_Pay8887 37m ago

Not super often day-to-day, mostly for chat, live dashboards, or collaborative stuff

1

u/Reinax 19h 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.

2

u/RealLamaFna 10h ago

To add, SignalR is pretty easy to implement.

1

u/CanIhazCooKIenOw 18h ago

Amazing how you went about judging others and finishing with pretty much the right answer: it depends.

It’s all about the tradeoffs and long polling in 2026 is still an option.

1

u/Reinax 18h ago

Bit reductive really bud. I’m adding a differing opinion to the sea of LLM slop and “use socket io”.

I guess I’ll repeat: The correct answer is indeed “it depends”. But it is not “too hard”, nor does it “not scale”, nor do you “need a third party” should you in fact realise you need it.

Long polling in 2026 is, in fact, ridiculous for any software used by a reasonable amount of people at a time with spiky usage periods. I’ve literally seen it bring a platform to its knees because the devs were glorified JS script kiddies. At least use SSE.

1

u/CanIhazCooKIenOw 16h ago

The funny thing is it’s not really that ridiculous and it should be considered as an option (even to discard).

As per the reasons about being too hard or not scaling, from your high horse, you could ask to expand on that. Maybe there’s specific scenarios where it might not.

1

u/Reinax 16h ago

What high horse? There’s nothing “high horse” about challenging opinions that my own experience causes me to disagree with, especially when they all say the same thing, made worse when it outright misinforms the OP and could literally cost them money. Having a sea of people say “it’s too hard” or “long polling is enough” is objectively bad advice, it encourages apathy toward learning something new, and reinforces bad practice. I mean hell, someone mentioned “just use Firebase” for god sake. I chose to write my own comment rather than reply to each of the 6 and counting individual comments that all referenced the main points I’m challenging.

0

u/ldn-ldn 1d 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 21h ago

Never.

Websockets don't make sense for most applications.

Only for things that need real time bidirectional communication.

I'm working on making a project have more real-time things

Like what?

You can use SSE to get real time displays, and then just normal requests for sending stuff.