WebSockets vs Long Polling vs SSE in System Design
By the BuildTheSystem team
Choosing how clients communicate with backend services is a core decision in technical interviews. Candidates often default to WebSockets for any feature that requires fast updates. Reaching for WebSockets when a simpler protocol works signals a lack of depth, while picking standard REST polling for a fast collaborative canvas creates bottleneck issues.
To pass senior architecture reviews and practice on platforms offering AI mock interviews for system design, you must understand the exact trade-offs between WebSockets, long polling, and Server-Sent Events (SSE). The right choice depends on message direction, update frequency, state overhead, and infrastructure complexity.
The Three Transport Protocols Compared
HTTP was built on a request-response pattern where the client initiates every exchange. Real-time features require servers to push data to clients without waiting for explicit requests. Engine ears solved this challenge using three primary strategies.
Long polling keeps a standard HTTP request open on the server until new data arrives or a timeout occurs. Once the server responds, the client immediately opens a new HTTP request. This approach works over standard infrastructure but incurs high overhead because every message requires a full HTTP request-response cycle with header parsing.
Server-Sent Events establish a single persistent HTTP connection over which the server streams text events to the client using the text/event-stream format. Communication flows strictly from server to client. Browser engines handle automatic reconnection natively, and SSE benefits from HTTP/2 connection multiplexing.
WebSockets begin with an HTTP Upgrade handshake that transitions the TCP connection into a full-duplex, bidirectional channel. Both client and server can send text or binary frames at any time with minimal frame overhead. However, maintaining millions of open TCP sockets requires specialized connection gateways and pub/sub routing layers.
| Feature | Long Polling | Server-Sent Events (SSE) | WebSockets |
|---|---|---|---|
| Direction | One-way (held request) | One-way (server to client) | Two-way (full duplex) |
| Protocol | Standard HTTP/1.1 or HTTP/2 | Standard HTTP/1.1 or HTTP/2 | WS / WSS (upgraded from HTTP) |
| Overhead | High (repeated headers) | Low (single HTTP stream) | Lowest (small frame headers) |
| Auto Reconnect | Manual client retry logic | Native browser handle | Manual client retry logic |
| Data Format | Any (JSON, XML) | Text only (UTF-8) | Text and Binary |
URL Shorteners and File Storage: Why Real-Time Pushes Are Wrong
In questions like designing a URL shortener (such as Bitly) or a file storage service (such as Dropbox), candidates sometimes suggest WebSockets to notify clients when a link is generated or a file finishes processing. This is an over-engineering mistake.
A URL shortener operates entirely on a standard request-response model. The client submits a long URL via an HTTP POST request, receives a shortened key, and stores it. Redirects use standard HTTP 301 or 302 headers. Adding persistent sockets to a URL shortener introduces connection state to a service that should remain stateless for maximum throughput.
File storage services handle large uploads asynchronously. When a user uploads a 500 MB file, the client sends chunked HTTP PUT requests directly to object storage using pre-signed URLs. The upload progress is tracked locally by the client based on bytes sent over the HTTP stream. If the server needs to notify another device that a file sync completed, standard polling every 30 seconds or an asynchronous push notification is sufficient.
If you introduce WebSockets into stateless systems, you force your load balancers to maintain persistent TCP tables for traffic that only occurs once every few hours. Keep simple systems stateless.
Chat Applications: Low-Latency Bidirectional Streams
In a chat application interview (such as WhatsApp or Slack), bidirectional communication is a hard requirement. Users continuously send messages to the server while receiving inbound messages from contacts and group channels.
WebSockets are the standard choice for messaging platforms. Assume a system with 10 million active users. If clients used long polling to receive messages, 10 million open requests would hit your backend web tier. Every incoming message would complete a request, forcing the client to re-establish a TCP connection, re-negotiate TLS, and send full HTTP request headers. This causes massive CPU overhead on load balancers.
With WebSockets, a client opens a single persistent wss:// connection to a dedicated connection gateway server. When User A sends a message to User B, the payload travels up User A's WebSocket to an ingestion server. The ingestion server publishes the event to a message broker like Kafka or Redis Pub/Sub. The broker routes the payload to the specific gateway instance holding User B's open socket, which pushes the message down the socket frame.
WebSockets cut protocol overhead from hundreds of bytes per HTTP header down to 2 to 10 bytes per frame. This bandwidth reduction is essential when supporting high message volumes.
Live Feeds and AI Streaming: One-Way Push with SSE
Not every real-time system requires the client to talk back over the same persistent pipe. For live sports scoreboards, stock tickers, notification centers, or LLM token streaming, communication is heavily asymmetric. The client requests data once, and the server pushes updates continuous over time.
Server-Sent Events are ideal for these use cases. When a user opens a live feed, the browser issues a standard HTTP GET request with an Accept: text/event-stream header. The server holds the response open, streaming event chunks as text lines.
Using SSE instead of WebSockets in these scenarios simplifies backend architecture:
- Standard HTTP Infrastructure: SSE streams travel over standard HTTP ports (80 and 443). They pass through standard reverse proxies, firewalls, and API gateways without custom protocol upgrade configurations.
- Native HTTP/2 Multiplexing: Under HTTP/2, a browser can open multiple SSE streams over a single underlying TCP connection, bypassing older browser connection caps.
- Built-in Resilience: Browser APIs automatically attempt to reconnect if an SSE stream drops, passing a
Last-Event-IDheader so the server can resume missed messages.
If the client needs to perform an action (like liking a live stream post), it sends a standard asynchronous HTTP POST request. You do not need a bidirectional socket just to handle occasional client writes.
Collaborative Editing: WebSockets for Operational Transformation
Collaborative document editors (such as Google Docs) present unique real-time demands. Multiple clients produce high-frequency edit operations (typing characters, moving cursors) while receiving operations from concurrent collaborators.
In this scenario, WebSockets are required because latency must stay low (under 50 milliseconds) to prevent text divergence. Edit operations use Operational Transformation (OT) or Conflict-Free Replicated Data Types (CRDTs). The server must receive client edits immediately, order them, and broadcast the transformed operations back to all connected clients.
Because edit state is tightly coupled to active editor sessions, connection management becomes critical:
- Session Affinity: Connection gateways use stateless pub/sub routers to mapping active document IDs to client socket IDs.
- Heartbeats: Ping and pong frame control messages detect stale sockets caused by dropped network connections or mobile handoffs.
- State Recovery: When a client reconnects after a socket drop, it sends its last applied sequence number over the new WebSocket to fetch missing delta operations.
Trade-Offs and Where Each Protocol Breaks Down
No transport mechanism works everywhere. You must explain failure modes clearly during an interview.
WebSocket Pitfalls
WebSockets are stateful. Standard HTTP application servers can scale horizontally by adding instances behind a round-robin load balancer because any server can answer any request. WebSockets break this model. A client's socket is bound to one specific server instance. If that server crashes, thousands of sockets drop simultaneously, creating a reconnect storm.
Furthermore, stateful connection servers consume high memory and file descriptors. Operating systems assign a file descriptor to every open socket. Without kernel tuning and memory allocation planning, connection nodes run out of memory long before CPU limits are reached.
SSE Limits
SSE only supports UTF-8 text payloads. Sending binary data requires Base64 encoding, which adds approximately 33% overhead to payload sizes. Additionally, older HTTP/1.1 proxy setups can suffer from browser limits that restrict simultaneous open connections per domain.
Long Polling Scaling Limits
Long polling suffers from request overhead and connection thrashing. When message rates are high, long polling devolves into rapid, repeated HTTP requests, combining the high latency of HTTP handshakes with the memory load of open requests.
What to Say Out Loud in the Interview
When presenting your system design, narrate your protocol choice by connecting user requirements directly to network trade-offs. You can practice building and talking through these diagrams on the free system design playground.
Use this structure when justifying your choice:
- Define the Data Flow Direction: State explicitly whether data flows one way or both ways. For example: "Our live notification feed only requires one-way updates from the server to the client."
- Evaluate Message Frequency and Latency: Compare expected message rates. "Because users receive stock price updates every second, standard short polling would generate unnecessary HTTP header traffic."
- Propose the Transport Protocol: State your protocol choice. "I am selecting Server-Sent Events over WebSockets because SSE streams over plain HTTP/2, provides automatic browser reconnection, and eliminates the need for bidirectional connection gateways."
- Address Backend State and Scaling: Explain how your backend handles connection state. "Because SSE and WebSockets hold open sockets, I will place a stateless Gateway layer in front of a Redis Pub/Sub cluster to route events to the correct client nodes."
Clear communication around protocol choice shows interviewers that you evaluate network efficiency, client complexity, and operational costs rather than simply picking the newest framework.
Frequently asked
When should I choose Server-Sent Events over WebSockets in an interview?
Choose Server-Sent Events when your application only needs one-way streaming from the server to the client, such as live sports updates, notification feeds, or token streaming. It uses standard HTTP, handles connection recovery automatically in the browser, and avoids the complexity of bidirectional socket state.
Why is long polling still mentioned in system design interviews?
Long polling serves as a fallback mechanism for networks or legacy clients that block persistent TCP upgrade requests. While inefficient at scale due to repeated HTTP connection setups, discussing it demonstrates that you understand browser compatibility and network constraints.
Can I practice real-time system design components on BuildTheSystem?
Yes. BuildTheSystem allows you to place components such as load balancers, API gateways, pub/sub queues, and databases on an interactive canvas during mock interviews, evaluating your architectural choices as you speak.
Rehearse this out loud, not just on paper
BuildTheSystem runs a live mock interview on a typed-component whiteboard — the interviewer listens, waits while you draw, and reacts the moment you connect something questionable.
Start a mock interviewRead next
Design Google Docs: Back-of-the-Envelope Estimates
A step-by-step back-of-the-envelope estimation guide for the Design Google Docs system design interview question, showing how capacity estimates shape architecture.
Rate Limiting Algorithms in System Design Interviews
A guide to rate limiting algorithms for system design interviews, comparing token bucket, fixed window, and sliding window with interview scenarios.
Design a News Feed: Mistakes That Cost Candidates the Round
Discover the common mistakes candidates make when asked to design a news feed, including fan-out traps, bad pagination, missing feed ranking, and weak interview narration.