Networking Essentials medium
When should you use WebSockets instead of REST/HTTP polling?
- A When you are primarily sending exceptionally large binary files that require the highest possible level of sequential disk I/O and data verification.
- B When you need to ensure that every individual data packet is encrypted with a unique, session-specific cryptographic key to prevent deep-packet inspection.
- C When you require real-time, bidirectional, and persistent communication between the client and server with minimal overhead for headers and handshakes.
- D When your application architecture relies on a highly-available, distributed pool of load balancers that must frequently rotate and refresh their internal routing tables.
Answer: C. When you require real-time, bidirectional, and persistent communication between the client and server with minimal overhead for headers and handshakes.
REST/HTTP is 'Request-Response'—the server only speaks when spoken to. For something like a real-time sportsbook or a chat app, you'd have to constantly 'Poll' the server (ask 'Is there an update?') every second, which is incredibly wasteful. WebSockets establish a single, persistent connection that stays open. This allows the server to 'Push' data to the client the instant it becomes available. By avoiding the overhead of repeating HTTP headers for every message and the latency of reopening connections, WebSockets provide a much smoother user experience for collaborative or live applications.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- What is the downside of enabling 'Sticky Sessions' (Session Affinity) on a Load Balancer?
- In WebRTC (P2P Mesh), why is a STUN server required?
- What is the fundamental difference between a Network Switch and a Router?
- In Cloud Networking (AWS), what is the limitation of VPC Peering compared to a Transit Gateway?
- Which protocol is ideal for real-time multiplayer gaming positions or Voice over IP (VoIP), and why?
- What is the purpose of the 'Time To Live' (TTL) field in an IP packet?