Which Real‑Time Communication Method Is Right for Your App? Short Polling, Long Polling, WebSocket, or SSE
This article compares four real‑time communication techniques—short polling, long polling, WebSocket, and Server‑Sent Events—detailing their advantages, drawbacks, latency, resource consumption, and ideal use cases to help developers choose the most suitable solution for their applications.
1. Short Polling
The browser sends HTTP requests at fixed intervals (e.g., every second). The server immediately returns the current data, regardless of updates.
Advantages: Simple to implement, excellent compatibility.
Disadvantages: High request frequency wastes resources; real‑time performance depends on polling interval.
Latency: High (depends on interval).
Suitable scenarios: High compatibility requirements, latency‑insensitive simple cases such as score live updates.
Example: a live‑score page where the browser polls for match updates and re‑renders when data changes.
2. Long Polling
The browser sends an HTTP request and the server holds the connection until data changes or a timeout occurs, then returns a response and the browser immediately opens a new request.
Advantages: Reduces useless requests, better real‑time performance than short polling.
Disadvantages: Server must maintain hanging connections; high resource consumption under heavy concurrency.
Latency: Medium (depends on data update frequency).
Suitable scenarios: Situations needing moderate real‑time performance where WebSocket/SSE cannot be used, e.g., message notifications.
Common use: configuration centers like Nacos and Apollo rely on long polling.
When a client requests, Nacos does not return immediately but hangs the request; if data changes within the wait period, it responds instantly, otherwise it replies after a timeout, prompting the client to re‑initiate long polling.
3. WebSocket
Based on TCP, it establishes a full‑duplex connection via an HTTP upgrade handshake ( Upgrade: websocket). This persistent connection enables bidirectional real‑time communication.
Advantages: Lowest latency, supports bidirectional interaction, bandwidth‑efficient.
Disadvantages: More complex to implement, requires explicit connection state handling.
Latency: Extremely low.
Suitable scenarios: Chat rooms, online games, collaborative editing, any high‑real‑time bidirectional interaction.
The author contributed to a live‑quiz feature for an e‑commerce platform, using WebSocket for real‑time updates.
4. Server‑Sent Events (SSE)
Built on HTTP, the server can actively push a data stream (e.g., Content-Type: text/event-stream) to the browser, which listens via the EventSource API.
Advantages: Native reconnection support, lightweight (HTTP‑based).
Disadvantages: Unidirectional (server → client), not supported by older IE browsers.
Latency: Low (server pushes instantly).
Suitable scenarios: Stock tickers, real‑time logs, any case where the server only needs to push data.
Classic example: DeepSeek chat interface uses SSE to receive AI responses.
5. Summary & Recommendation
Choose the technique based on required compatibility, latency, and interaction model:
Need simple compatibility → Short Polling.
Need moderate real‑time without full duplex → Long Polling.
Need server‑push only → SSE.
Need full‑duplex real‑time interaction → WebSocket.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Su San Talks Tech
Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
