Author(s): Leapfrog Technology

Originally published on Towards AI.

WebSockets are deceptively simple. Every connected user maintains a persistent connection to the server, and each connection continuously occupies server resources such as memory, CPU cycles, network buffers, and application state. Unlike traditional HTTP requests, WebSocket connections are long-lived and stateful, meaning resource consumption grows almost linearly with the number of users. You can, however, derive a simple mathematical model to introduce the problem.

The fundamental problem

Every active WebSocket connection consumes server resources. For each connection, a Node.js process maintains: