04 / 05

How are websockets different from HTTP calls?

Difficulty: 5/10
connection model, real-time communication, protocol overhead

HTTP is unidirectional where the client sends the request and the server sends the response.HTTP is a stateless protocol that runs on top of TCP which is a connection-oriented protocol it guarantees the delivery of data packet transfer using the three-way handshaking methods and re-transmits the lost packets.

HTTP can run on top of any reliable connection-oriented protocol such as TCP, SCTP. When a client sends an HTTP request to the server, a TCP connection is open between the client and server and after getting the response the TCP connection gets terminated, each HTTP request opens a separate TCP connection to the server,

WebSocket is bidirectional, a full-duplex protocol that is used in the same scenario of client-server communication, unlike HTTP it starts from ws:// or wss://. It is a stateful protocol, which means the connection between client and server will keep alive until it is terminated by either party (client or server). After closing the connection by either of the client and server, the connection is terminated from both ends.

Once the communication link establishment and the connection are opened, message exchange will take place in bidirectional mode until the connection persists between client-server. If anyone of them (client-server) dies or decide to close the connection is closed by both of the party.

Scenario Questions

0-2 years experience

  1. 1You need to add a live chat feature to a Node.js app. Would you choose WebSocket or regular HTTP requests, and why?
  2. 2If a client opens a WebSocket connection and then sends a normal HTTP GET request to the same endpoint, what will happen on the server side?

2-5 years experience

  1. 1Our real‑time dashboard switched from HTTP polling to WebSockets, but some users still see delayed updates. What could be causing this?
  2. 2Explain how you would implement a fallback to HTTP long‑polling in a Node.js service that primarily uses WebSockets.
  3. 3During a load test the WebSocket server runs out of file descriptors. What does this tell you about how WebSockets differ from HTTP handling in Node?

5-8 years experience

  1. 1Design a scaling strategy for a Node.js WebSocket service that must support 100k concurrent connections while still handling occasional HTTP API calls.
  2. 2What are the security implications of upgrading an HTTP connection to a WebSocket, and how would you mitigate them in a multi‑tenant Node.js platform?

8+ years experience

  1. 1Our legacy system uses HTTP polling for real‑time updates. We want to migrate to a WebSocket‑based architecture across multiple services and teams. How would you plan the migration to minimize risk and ensure backward compatibility?
  2. 2Discuss the trade‑offs of using a centralized WebSocket broker versus a peer‑to‑peer WebSocket mesh in a large‑scale microservices environment.

Follow-up Questions

  • How does the initial HTTP upgrade handshake affect latency compared to a plain HTTP request?
  • Can you compare resource usage on the server for 10k concurrent WebSocket connections versus 10k HTTP polling clients?
  • What happens if the WebSocket connection is interrupted mid‑stream?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.