Compare Short Polling, Long Polling, SSE, and WebSocket.

Topic: microservices, Real-Time Communication. Level: Intermediate.

Answer

- **Short polling**: client pulls on an interval. Simple; high latency + waste. Low-frequency updates. - **Long polling**: server holds request until data. Near real-time over HTTP; connection churn. Fallback when WebSocket unavailable. - **SSE**: server→client stream over HTTP; auto-reconnect; text only, one-way. Feeds/notifications. - **WebSocket**: full-duplex persistent connection; binary+text; lowest overhead per message; stateful, harder to scale. Chat/games/collab. Rule: one-way server push → SSE; two-way interactive → WebSocket; must work through restrictive proxies with minimal setup → long polling; trivial/rare updates → short polling; P2P media → WebRTC. ```text Direction Transport Latency Complexity Best for Short polling C->S pull HTTP high very low rare updates Long polling C<->S (held) HTTP low-med low WS fallback SSE S->C stream HTTP low low feeds/notifs WebSocket C<->S duplex TCP(ws) lowest medium chat/games WebRTC P2P UDP/SRTP lowest high video/voice ```