Web Development

What are WebSockets and when should you use them?

How WebSockets keep one connection open so a server can push live updates the moment they happen, and when to choose them over polling or Server-Sent Events.

  • 6 min read
  • 5 questions
  • +35 XP
Transcript

Web Sockets, explained by cats. Kitty builds a tuna tracker. Cats want live updates. New tuna arrivals. Right now. With normal API requests, Kitty keeps asking: “Any tuna?” “Now?” “Now?” That’s noisy. So Kitty opens a WebSocket connection. One connection.

Kept open. The server and Kitty stay connected. They can talk anytime. New tuna arrives. Server pushes the update. No asking. WebSockets are two-way. Real-time. Fast. Perfect for chats. Live feeds. Multiplayer cat games. which results in Less waiting. and More tuna.