SD Core

WebSocket

Persistent bidirectional TCP connection — low-latency push for chat, live maps, gaming, and streaming tokens.

Interview tip Lead with a 30-second definition, then one real system example and name 2–3 designs where WebSocket is non-negotiable.

① What it is (30 seconds)

Persistent bidirectional TCP connection — low-latency push for chat, live maps, gaming, and streaming tokens.

② How it works in system design

HTTP upgrade handshake. Server pushes without client polling. Connection state per socket — needs sticky routing or shared pub/sub backplane (Redis) across servers.
Typical placement
ClientEdge / GatewayWebSocketServicesData stores

③ Concrete system design example

Scenario: WhatsApp Web: WebSocket to chat server. Message arrives → push to recipient sockets subscribed to room channel via Redis pub/sub between nodes.

④ Important interview Q&A

QuestionAnswer
WebSocket vs SSE?WebSocket bidirectional; SSE server→client only, simpler over HTTP/2.
Scale WebSockets?Millions of connections: connection registry sharded, pub/sub bridge between nodes, LB with TCP pass-through.
Reconnect?Client resubscribes with last_seen message_id; server replays missed from short buffer.

⑤ Seen in these system designs

In interviews, after explaining the concept, say: "This shows up directly in …" and link two designs.

⑥ Revision checklist

  • Upgrade handshake
  • Pub/sub backplane
  • Sticky vs shared state
  • Reconnect + replay
websocketreal-timepush