"매 single TCP connection over HTTP upgrade — 매 full-duplex, low-overhead binary/text framing 의 realtime 표준". 2011 RFC 6455, 2026 WebTransport (HTTP/3) 가 등장했지만 WS 는 여전히 ubiquitous. 매 chat, collaborative editing, live dashboards, gaming 의 backbone.
매 핵심
매 Lifecycle
HTTP GET + Upgrade: websocket + Sec-WebSocket-Key.
Server 의 101 Switching Protocols + Sec-WebSocket-Accept.
constsub=redis.duplicate();awaitsub.subscribe('room:*',(msg,channel)=>{constroom=channel.split(':')[1];server.publish(`room:${room}`,msg);// 매 local connections 만
});// publisher (any node)
awaitredis.publish(`room:${room}`,JSON.stringify(payload));
import*asYfrom'yjs';import{WebsocketProvider}from'y-websocket';constdoc=newY.Doc();constprovider=newWebsocketProvider('wss://yjs.example/sync',`doc:${docId}`,doc);consttext=doc.getText('content');text.observe(e=>render(text.toString()));text.insert(0,'Hello');// 매 CRDT-merged 매 모든 client
Backpressure
ws.send(payload);if(ws.bufferedAmount>1_000_000){ws.close(1013,'backpressure');// drop slow client
}
매 결정 기준
상황
Approach
Server → client only stream
SSE (simpler, HTTP/2)
Bidirectional, < 10k conn / node
WebSocket on Bun/Node
100k+ conn / node
uWebSockets.js, Go (gobwas/ws), Rust
Managed pub/sub
Centrifugo, Ably, Pusher
Collab editing
Yjs / Automerge over WS
Low-latency game
WebTransport (HTTP/3)
기본값: WSS + JWT in first message + Redis pub/sub fanout + 30s heartbeat + exponential reconnect.