Choosing Socket.io Over Raw WebSockets for Control-Plane Worker Node Orchestration

NetworkingWebSocketsInfrastructureRealtime

Building DockHostV2 required bidirectional communication between the central control plane web server and remote backend worker node daemons to stream container terminal sessions.

Adopt Socket.io with custom namespace rooms rather than standard raw WebSocket connections.

Raw WebSockets (`ws` npm package)

Pros
  • Lower bundle size
  • Pure native protocol implementation
Cons
  • Manual heartbeats and reconnection handling required
  • Complex multiplexing for terminal streams

gRPC Streams

Pros
  • Strongly typed schema
  • High performance
Cons
  • More complex web browser integration
  • Higher setup overhead for small worker fleets

Socket.io's automatic reconnection, heartbeat failure detection, room namespaces, and fallback transports significantly reduced boilerplate code for managing multi-worker node connections.

Technical Reasoning

Streaming interactive shell sessions requires bulletproof connection management. Network hiccups shouldn’t hang container PTY streams or leave zombie Docker containers running on worker nodes. Socket.io provided out-of-the-box ping/pong heartbeats and seamless client reconnection.