Script Valley
WebSockets & Real-Time Applications
How WebSockets Actually WorkLesson 1.1

What is a WebSocket and why HTTP falls short for real-time

HTTP request-response cycle, polling vs push, persistent connections, half-duplex vs full-duplex, latency comparison, use cases for WebSockets

Why HTTP Alone Cannot Do Real-Time

HTTP is a request-response protocol. The client always initiates. The server cannot push data to a client that has not asked for it. For real-time features โ€” chat, live scores, collaborative editing โ€” this creates three bad patterns:

  • Short polling: Client asks every N seconds. Wastes bandwidth, adds latency.

  • Long polling: Client holds a request open until the server has something. Better, but still one message per round trip.

  • Server-Sent Events: One-way server push. Useful but not bidirectional.

WebSockets solve this with a single, persistent, full-duplex TCP connection. Once open, either side can send a frame at any time with no HTTP overhead on each message.

When to Use WebSockets

WebSockets are the right tool when latency matters and data flows in both directions:

  • Chat and messaging

  • Live dashboards and financial tickers

  • Multiplayer games

  • Collaborative tools (Figma, Google Docs)

  • Real-time notifications

If data only flows server-to-client and you can tolerate occasional drops, Server-Sent Events are simpler. If updates are infrequent and latency tolerances are high, REST polling is fine. Use WebSockets deliberately, not by default.

Up next

The WebSocket handshake explained step by step

Sign in to track progress

What is a WebSocket and why HTTP falls short for real-time โ€” How WebSockets Actually Work โ€” WebSockets & Real-Time Applications โ€” Script Valley โ€” Script Valley