System Design (50 Qs)•Part 4: API Design, Security & Edge Networking (37 - 43)
WebSockets vs Server-Sent Events (SSE) vs Long Polling.
In Simple Words:
- WebSockets: Full-duplex bidirectional TCP communication. Best for gaming, collaborative editing, and chat.
- Server-Sent Events (SSE): Unidirectional server-to-client streaming over standard HTTP. Built-in reconnection. Best for live stock tickers, LLM streaming output, and notifications.
- Long Polling: Legacy fallback where client holds an HTTP request open until the server responds.