WebSockets enable real-time, bidirectional communication between client and server over a persistent connection. Unlike HTTP (request → response → close), WebSockets stay open—server can push updates to client instantly. Perfect for chat apps, live dashboards, multiplayer games, stock tickers. HTTP: client asks "any updates?" every 5 seconds (polling). WebSockets: server says "here's an update!" when it happens. Much more efficient.
Use WebSockets for real-time features: chat/messaging, live notifications, collaborative editing (Google Docs style), live dashboards, multiplayer games, or stock/crypto tickers. Don't use for standard CRUD APIs—HTTP is simpler. Don't use if updates can wait seconds (polling or Server-Sent Events work fine). Common libraries: Socket.io, ws, Pusher.
System Design Patterns
Real-time two-way updates