Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
Web, API & dataMiddleOccasionalTheory

What is WebSocket, where is it used, and when would you choose it instead of ordinary HTTP, polling or Server-Sent Events?

Answer

WebSocket is a persistent full-duplex protocol that lets both client and server send messages at any time over one long-lived connection. It is useful for chats, live notifications, collaborative editing, games, dashboards, trading feeds, telemetry and other interactive low-latency features. Ordinary HTTP is better for normal request/response CRUD. Polling is simpler for infrequent updates, while SSE is often sufficient when only the server needs to push events to a browser. The choice should follow communication direction, frequency, latency and operational complexity rather than the label real-time.

Strong answer includes

  • persistent bidirectional connection
  • concrete real-time use cases
  • compares WebSocket with polling and SSE

Practical example

A dashboard refreshes once every five minutes, so replacing a normal HTTP request with WebSocket would add connection management without much benefit. A collaborative editor receiving edits from many users continuously is a much stronger WebSocket case.

#websocket#real-time#sse#polling

Sources

MDN HTTP referenceMozilla · HTTP methods, messages, status codes, headers, cookies and cachingAsyncAPI Specification 3.0.0AsyncAPI Initiative · Message-driven API channels, operations, messages, schemas and bindingsDOU — QA interview: 250+ questionsDOU · Coverage signal across Junior, Middle, Senior, AQA, web, mobile and practical topics