WebSockets vs Server-Sent Events (SSE)
Two protocols for realtime data — each with the right use case.
WebSockets and SSE both push data from server to client in real time, but they work differently. Understanding the difference helps you choose the right protocol — or know when you need a managed solution like Apinator.
WebSockets: Bidirectional
A WebSocket is a persistent, full-duplex TCP connection. Both client and server can send messages at any time. Ideal for chat, games, presence, and collaborative editing.
SSE: Server-Push Only
Server-Sent Events stream data one-way from server to client over HTTP. The browser cannot send data back over the SSE connection. Best for feeds, dashboards, and live scores.
WebSockets Scale Differently
Persistent connections require sticky sessions or a pub/sub layer (like Redis) to fan out messages across nodes. SSE over HTTP/2 can be load-balanced more easily.
SSE Has Browser Limits
Browsers allow only 6 concurrent SSE connections per origin under HTTP/1.1. HTTP/2 removes this limit. WebSockets have no such constraint.
WebSockets Need Auth Handling
SSE uses standard HTTP cookies and headers for auth. WebSockets require custom auth — Apinator handles this with HMAC-signed channel tokens.
When to Use Apinator
Apinator uses WebSockets for full bidirectional channels, presence, and client events — use cases where SSE falls short.
Apinator vs SSE
| Feature | Apinator | SSE |
|---|---|---|
| Direction | Bidirectional | Server → Client only |
| Protocol | WebSocket (TCP) | HTTP streaming (text/event-stream) |
| Browser reconnect | Client SDK handles it | Built into browser |
| Binary messages | JSON text only | |
| Client → Server messages | ||
| Presence / who is online | ||
| HTTP/2 multiplexing | ||
| Load balancer friendly | With sticky sessions | Stateless |
| Good for chat / games | ||
| Good for dashboards / feeds |
Side-by-Side Comparison
The same "server pushes data" use case, implemented with SSE and with Apinator WebSockets.
// SSE — server-to-client only, no send-back
const sse = new EventSource('/api/stream')
sse.onmessage = (e) => handleData(JSON.parse(e.data))
// sse.send() — not possible, SSE is read-only
// Apinator WebSockets — bidirectional, presence-aware
import { Apinator } from '@apinator/client'
const client = new Apinator({ appKey: 'APP_KEY', cluster: 'eu', authEndpoint: '/api/realtime/auth' })
const ch = client.connect().subscribe('presence-dashboard')
// Receive server events
ch.bind('update', (data) => handleData(data))
// Send a client event back — not possible with SSE
ch.trigger('client-cursor', { x: 120, y: 340 })Frequently Asked Questions
From the blog
How to Build a Crypto / Stock Price Ticker with WebSockets
Build a live price ticker that updates in real time — polling an external price feed on the server and pushing updates to all clients instantly via WebSockets.
WebSockets vs HTTP Polling
Polling gets the job done until it doesn't. Here's an honest comparison of WebSockets and HTTP polling — latency, server load, complexity, and when to use each.
What Is a WebSocket?
WebSockets let servers push data to clients the moment it changes — no polling, no waiting. Here's how they work, what they're good for, and when to use them.
How the WebSocket Handshake Works
The WebSocket connection starts as HTTP and upgrades to a persistent socket. Here's exactly what happens during the handshake — headers, keys, and all.
WebSocket Protocol Explained
A practical guide to the WebSocket protocol — how connections are established, how frames are structured, what opcodes do, and what all of this means when you're building realtime apps.
Ready to get started?
Completely free, no credit card required. Deploy in minutes.