Networking & Protocols • WebSocket & Real-time CommunicationMedium⏱️ ~3 min
Protocol Alternatives and Trade Offs: SSE, Long Polling, HTTP/2, and Push Notifications
While WebSocket provides full duplex communication, several alternative protocols offer different trade offs for real time systems. Server Sent Events (SSE) is a one way server to client streaming protocol over standard HTTP, providing automatic reconnection with last event ID tracking, excellent compatibility behind proxies and CDNs, and simpler semantics than WebSocket. SSE is ideal for dashboards, log streaming, and notifications where client to server communication is rare or handled via separate HTTP requests. However, SSE lacks native binary support (everything is text encoded) and cannot push from client to server without additional mechanisms, making it unsuitable for bidirectional applications like chat or collaborative editing.
Long polling predates WebSocket and works universally through legacy proxies by making HTTP requests that the server holds open until data is available or a timeout occurs. It provides near real time delivery with broad compatibility but adds significant header overhead (each poll is a full HTTP request/response cycle) and typically exhibits higher tail latency due to connection setup costs. Long polling is appropriate for low frequency events, environments with strict firewall restrictions, or as a fallback mechanism when WebSocket connections fail. HTTP/2 streaming and gRPC bidirectional streaming provide efficient multiplexing of many streams over a single connection with built in flow control and backpressure, excellent for service to service communication and native mobile apps. However, browser support for client driven bidirectional gRPC is limited without adapters or workarounds, making it less viable as a universal web client solution.
For mobile applications, push notifications via Apple Push Notification Service (APNs) or Firebase Cloud Messaging (FCM) enable message delivery when apps are backgrounded or the device is asleep, scenarios where maintaining persistent WebSocket connections would drain battery or be impossible due to OS restrictions. Push notifications have variable latency (typically seconds to minutes), no strict ordering guarantees, and are unsuitable for high frequency updates or strictly ordered streams. Production architectures often combine protocols: WebSocket or SSE for foreground active sessions, falling back to long polling when WebSocket is blocked, and degrading to push notifications when the app backgrounds, using resume tokens or sequence numbers to catch up on missed events when returning to the foreground.
💡 Key Takeaways
•Server Sent Events (SSE) provides one way server to client streaming with automatic reconnection, ideal for dashboards and logs but lacks bidirectional and native binary support
•Long polling works universally through legacy proxies but adds header overhead and higher tail latency, best used for low frequency events or as a fallback mechanism
•HTTP/2 and gRPC streaming offer efficient multiplexing with backpressure for service to service and native mobile, but have limited browser support for bidirectional client use
•Push notifications (APNs/FCM) enable mobile background delivery with variable latency (seconds to minutes), unsuitable for high frequency or strictly ordered streams
•Production systems combine protocols: WebSocket or SSE for foreground, long polling as fallback, push notifications for background, with resume tokens to reconcile state
•WebSocket excels for many to many fan out with sub 250 ms latency requirements and frequent bidirectional updates like chat, presence, and collaborative editing
📌 Examples
Meta Messenger maintains a single persistent connection for presence, typing, receipts, and control messages while active, with tuned keepalives for mobile networks, and degrades to push notifications when backgrounded to preserve battery across billions of devices
Salesforce historically used Bayeux CometD long polling for streaming API, later adding gRPC based pub/sub for lower latency and higher throughput, with resumability via replay IDs supporting sustained rates of hundreds to tens of thousands of events per second