Scaling Websockets to 1 Million
Real-time agent interaction requires Websockets. But standard implementations choke at scale. Here is how we handled the load.
The C10k Problem? Try C1M.
Node.js manages connections well, but the garbage collector pauses were killing us.
Solution 1: uWebSockets.js
We migrated from socket.io to uWebSockets.js. It's written in C++ and binds to Node. The memory footprint dropped by 80%.
Solution 2: Redis Sharding
We use Pub/Sub to sync state across clusters. A single Redis instance became the bottleneck. We moved to Redis Cluster and sharded channels by workspace_id.
Solution 3: Nginx Tuning
We had to increase the open file descriptors limit (ulimit -n) and tune the worker_connections.
1# nginx.conf snippet 2events { 3 worker_connections 20000; 4 multi_accept on; 5}
Scaling is hard, but steady.