Skip to content
IT glossary
BackendUpdated December 3, 2026

WebSocket vs HTTP

WebSocket или HTTP

With HTTP, a client sends a request and the server returns a response. WebSocket keeps a channel open so either side can send a message without a separate request for each update.

The key difference

HTTP is a good fit when a client wants a specific result: fetch a profile, submit an order, or download a file. WebSocket is useful when either side needs to send updates as they happen. In a shared editor, for instance, a browser can send a local edit and receive someone else's edit over the same channel, without polling for changes.

What happens on the wire

HTTP's request–response model doesn't mean every request needs its own connection. HTTP/1.1 can reuse a connection, and HTTP/2 can carry several exchanges concurrently on one connection. An HTTP response can also stay open and stream data over time. The distinction is that the stream is still part of a response the client requested.

A WebSocket session over HTTP/1.1 starts with an HTTP request containing Upgrade: websocket. If the server accepts, it returns 101 Switching Protocols. From then on, the two endpoints exchange WebSocket frames carrying text or binary messages, rather than sending HTTP requests and responses. With HTTP/2, WebSocket uses an extended CONNECT instead of the HTTP/1.1 upgrade. The wss:// scheme indicates that the session is protected by TLS.

Example: a shared document

When someone opens a document, the browser can fetch its current contents with GET /documents/42, then use WebSocket to send edits and receive changes from other people. The application can number revisions so that, after a disconnect, the browser can ask for everything after its last applied revision or fetch a fresh copy. A new WebSocket connection doesn't automatically replay missed edits.

Choosing a transport

  • Use ordinary HTTP when requests are independent or updates can wait. For a background export, polling a status endpoint every few seconds may be all you need.
  • Consider Server-Sent Events (SSE) when the browser needs prompt updates from the server but rarely sends anything back. SSE streams events in an HTTP response; the browser can still send commands in separate HTTP requests.
  • Use WebSocket when frequent, low-delay messages flow in both directions. It avoids a separate HTTP exchange per message, but you still need to manage open connections, reconnects, and application-level recovery.

How it comes up in interviews

If asked how you'd deliver live updates, clarify who sends them, how often, and how much delay is acceptable before picking a protocol. Then explain what happens when a client goes offline or when thousands of clients reconnect at once. In a multi-server WebSocket setup, a user may be connected to a different server than the one that produced the event. A shared message broker is one way to get that event to the server holding the user's connection.