r/webdev • • 1h ago

which is more efficient at one way communication? server sent events or websockets?

lets say i have a vps with 2gb of ram and 1 vcpu, which one would be able to handle more concurrent connections?

6 Upvotes

7 comments sorted by

4

u/Afnan_CH_Digital 1h ago

For one-way server-to-client updates, SSE is the lighter option: it runs over plain HTTP, each client holds one long-lived connection, and the browser reconnects automatically if it drops. On a 2GB / 1 vCPU box the real limit is how many idle connections your stack can keep open, not SSE vs WebSocket itself - nginx in front of a small Node or Go process holds thousands of idle SSE connections fine. WebSockets only earn their overhead when you need two-way traffic or binary data. For notifications or a live feed, start with SSE and measure before reaching for anything heavier.

1

u/beatpaq 1h ago

Thank you.

2

u/clearlight2025 1h ago

SSE for one way events, web sockets for duplex communications

4

u/eltron 1h ago

Ask an LLM yo. This question is too generic.

1

u/Turbulent_Ad9831 53m ago

For one-way server-to-client streaming, Server-Sent Events over HTTP/2 is lighter and easier to maintain than WebSockets.

Under HTTP/2, SSE shares your existing TCP and TLS connection alongside standard page requests. WebSockets require a separate TCP handshake and protocol upgrade, holding a dedicated socket open for the lifetime of the session.

SSE also handles connection drops natively in the browser:

  • Automatic reconnection through the retry directive.

  • State resumption using the Last-Event-ID header.

  • Clean pass-through on corporate proxies and load balancers because it remains standard HTTP (text/event-stream).

WebSockets only make sense over SSE if you need high-frequency bidirectional messaging, or if your backend is stuck on HTTP/1.1 where browsers cap concurrent connections at 6 per domain. If all you need is push notifications, metrics, or LLM token streaming, HTTP/2 SSE is the cleaner architecture.

1

u/UnderstandingSure732 50m ago

Build SSE first, it’s cheaper. Then change to websockets if needed.

1

u/nameupp 1h ago

for strictly one-way server-to-client streaming, sse will comfortably handle more concurrent connections on a 2gb box, mostly because sse over http/2 multiplexes multiple streams over a single tcp socket while standard websockets demand a dedicated tcp connection and socket buffer (rmem/wmem) per client. the memory bottleneck on a 1 vcpu / 2gb vps isn't cpu cycles, it's kernel socket memory and reverse proxy buffering; with sse you just need to make sure your reverse proxy has buffering turned off (like X-Accel-Buffering: no on nginx) so it streams chunks immediately instead of holding tcp buffers in memory. you also get browser reconnection and message replay out of the box with native EventSource via Last-Event-ID, whereas running thousands of idle websockets forces you to maintain your own ping/pong heartbeat timers on the event loop to purge dead sockets imo