Choosing Socket.io Over Raw WebSockets for Control-Plane Worker Node Orchestration
Context
Building DockHostV2 required bidirectional communication between the central control plane web server and remote backend worker node daemons to stream container terminal sessions.
Decision
Adopt Socket.io with custom namespace rooms rather than standard raw WebSocket connections.
Alternatives Considered
Raw WebSockets (`ws` npm package)
- Lower bundle size
- Pure native protocol implementation
- Manual heartbeats and reconnection handling required
- Complex multiplexing for terminal streams
gRPC Streams
- Strongly typed schema
- High performance
- More complex web browser integration
- Higher setup overhead for small worker fleets
Reasoning
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.