Software development · Realtime

WebSockets, SSE or WebRTC? Choosing realtime transport for your app

When to use WebSockets, Server-Sent Events or WebRTC for chat, notifications, live dashboards and calls, with lessons from building ChatLOL and GoFloe.

Use Server-Sent Events when the server only needs to push updates to the browser, such as notifications or live dashboards. Use WebSockets when both sides send messages often, such as chat, presence and multiplayer. Use WebRTC for audio, video and screen sharing, usually through a media server once a call has more than a few people.

Realtime features are at the heart of two products I've built: ChatLOL, a social network with live lounges and chat, and GoFloe, which has team chat, live meetings and screen sharing built in. The question I get asked most by clients planning something similar is which technology to use. The honest answer is usually more than one.

Server-Sent Events: the underrated option

SSE is a plain HTTP response that stays open while the server writes events into it. The browser side is a few lines:

const events = new EventSource('/api/stream');
events.addEventListener('invoice.paid', (e) => {
  const invoice = JSON.parse(e.data);
  showToast(`Invoice ${invoice.number} was paid`);
});

What you get for free: automatic reconnection, a Last-Event-ID header so the server can resend anything missed, and plain HTTP that works through proxies, CDNs and corporate firewalls. Over HTTP/2 or HTTP/3, many streams share one connection, so the old limit of six connections per domain no longer bites.

Use it for: notifications, activity feeds, progress bars for long jobs, live dashboards and streaming AI responses. If the client only occasionally sends something back, a normal POST request alongside the stream is perfectly fine.

WebSockets: true two-way messaging

A WebSocket upgrades an HTTP connection into a persistent, full-duplex channel. Both sides can send at any time with very little overhead per message.

Use it for: chat, typing indicators, presence ("who's online"), collaborative editing and games, anywhere the client sends many small messages.

What you have to build yourself: reconnection with backoff, re-subscribing to rooms after a reconnect, heartbeats so dead connections are noticed, and a way to fetch messages missed while disconnected. Every chat feature I've shipped has a "catch up since message ID X" endpoint for exactly this reason.

WebRTC: media, peer to peer or via a server

WebRTC is built for audio, video and screen sharing with very low latency. It handles the hard parts of media (codecs, echo cancellation, bandwidth adaptation) and can connect browsers directly.

Peer to peer works well for one-to-one calls. Beyond three or four participants, each person would have to upload their video to everyone else, which quickly breaks on normal connections. Group calls use a Selective Forwarding Unit (SFU): everyone sends one stream to the server, which forwards it to the others. Open-source options include LiveKit and mediasoup. You will also need a TURN server for the minority of users behind networks that block direct connections.

WebRTC still needs a separate signalling channel to set calls up, and that is usually your existing WebSocket.

Scaling is about fan-out, not connections

A single modern server can hold tens of thousands of idle WebSocket or SSE connections. What gets hard is delivering a message to the right connections when they are spread across several servers. The usual pattern is a shared pub/sub layer (Redis, NATS or your database's notification feature): each app server subscribes to the rooms its connected users care about and forwards messages to them.

Design your message format and room model early. Changing them once mobile apps are in users' hands is much harder than changing your transport.

A quick decision guide

  • Server pushes, client rarely talks back: SSE.
  • Lots of small messages both ways: WebSockets.
  • Voice, video or screen sharing: WebRTC, with an SFU for groups and TURN for difficult networks.
  • Not sure yet: start with SSE plus normal HTTP requests. It's the simplest to run and easy to swap later.

FAQ

Is SSE better than WebSockets?

Neither is better overall. SSE is simpler and more robust when data mainly flows from server to browser. WebSockets are better when the client also sends frequent messages, as in chat or games.

Do I need WebRTC for a chat app?

Only for voice or video. Text chat, presence and typing indicators run perfectly over WebSockets. WebRTC can be added later for calls, using the WebSocket for signalling.

How many WebSocket connections can one server handle?

Tens of thousands of mostly idle connections are realistic on a modest server with a suitable runtime. The practical limit is usually how much work each message triggers, not the number of open connections.

Keep reading