What is full-duplex communication and how do WebSockets provide it?
Understand full-duplex communication and how WebSockets provide it — a persistent two-way connection for instant real-time messaging between client and server.
Expected Interview Answer
Full-duplex communication means both parties can send and receive data simultaneously over the same connection, and WebSockets provide it by keeping a single persistent TCP connection open through which the client and server exchange independent message frames at any time.
Traditional HTTP is half-duplex request/response: the client asks and waits for the server to answer before anything else happens. After a one-time HTTP upgrade handshake, a WebSocket switches to a bidirectional channel where framed messages flow in both directions independently, with no need to wait for a matching request, enabling instant chat, live dashboards, and multiplayer interactions.
- Simultaneous two-way messaging with no waiting
- One persistent connection instead of many requests
- Low latency for real-time updates
- Supports both text and binary frames
- Ideal for chat, gaming, live feeds and collaboration
AI Mentor Explanation
A half-duplex system is like using a single walkie-talkie channel where only one person may speak at a time and must say 'over' before the other can reply. Full-duplex, which WebSockets provide, is like the captain and wicketkeeper both talking freely on an open headset — each can speak and listen at the very same moment without ever waiting for a turn.
Step-by-Step Explanation
Step 1
Start with HTTP
The client sends an HTTP request carrying an Upgrade header to request a WebSocket connection.
Step 2
Handshake completes
The server responds with 101 Switching Protocols, and the connection becomes a WebSocket.
Step 3
Persistent channel opens
One TCP connection stays open, ready for messages in both directions.
Step 4
Independent framing
Client and server send framed messages whenever they want, with no request/response pairing.
Step 5
Simultaneous flow
Because sends and receives are independent, both sides transmit at the same time — true full-duplex.
What Interviewer Expects
- Correct definition of full-duplex vs half-duplex
- Understanding that HTTP is request/response by default
- Knowledge of the WebSocket upgrade handshake
- Awareness that WebSocket frames are independent of each other
- Real-world use cases like chat and live dashboards
Common Mistakes
- Confusing full-duplex with simply being 'fast'
- Thinking WebSockets still require a request for each server message
- Calling standard HTTP full-duplex
- Forgetting that a WebSocket begins as an HTTP upgrade
Best Answer (HR Friendly)
“Full-duplex means both sides of a conversation can talk and listen at the same time, like a phone call rather than a walkie-talkie. WebSockets keep one connection open so the browser and server can send messages to each other instantly, which powers live features like chat.”
Code Example
const ws = new WebSocket('wss://example.com/socket')
// Receive from server at any time
ws.onmessage = (e) => console.log('Server:', e.data)
// Send to server at any time — no waiting for a request
ws.onopen = () => {
ws.send('hello')
setInterval(() => ws.send('ping'), 1000)
}Follow-up Questions
- How does the WebSocket handshake upgrade from HTTP?
- What is the difference between full-duplex and half-duplex?
- Why is HTTP request/response considered half-duplex?
- How do WebSocket frames differ from HTTP messages?
- What real-time features rely on full-duplex communication?
MCQ Practice
1. What does full-duplex communication mean?
Full-duplex allows both parties to transmit and receive simultaneously over the same connection.
2. How does a WebSocket connection begin?
A WebSocket starts as an HTTP request with an Upgrade header; the server replies with 101 Switching Protocols to open the socket.
3. Why is standard HTTP considered half-duplex?
HTTP follows a request/response pattern, so the two sides take turns rather than sending simultaneously.
Flash Cards
What is full-duplex? — Both parties can send and receive data at the same time over one connection.
How do WebSockets enable full-duplex? — They keep one persistent connection open with independent frames flowing both ways.
Is HTTP full-duplex? — No — it is half-duplex request/response, one side waits for the other.
What status code opens a WebSocket? — 101 Switching Protocols, after an HTTP Upgrade handshake.