Compiling
Article

Running WebSocket Infrastructure on a VPS

Running WebSocket Infrastructure on a VPS

Self-hosting a real-time stack on a VPS is a reasonable choice when you want control over cost, data, and behavior. It stops being reasonable if you underestimate how the process behaves under real traffic.

Connections are memory

Every open socket is a bit of RAM plus a file descriptor. Raise the system and per-process descriptor limits early, measure memory per thousand connections on your actual payloads, and size the box from that number rather than a guess.

Supervision is not optional

Run the socket server under a supervisor that restarts it on crash and on deploy, with a back-off so a crash loop does not hammer the CPU. Log the restart reason. A server that silently dies at 3am and comes back at 9am when someone notices is worse than one that restarts in two seconds.

Terminate TLS where it is cheapest

Let a reverse proxy handle certificates and TLS, and pass plain traffic to the socket process on localhost. Certificate renewal then has nothing to do with your application deploys.

Watch the right metrics

Active connections, messages per second, event-loop lag, and memory trend. If loop lag climbs while CPU looks fine, you have a slow handler blocking everything else, and that is the bug to chase.

Done with those guardrails, a single modest VPS carries a surprising amount of real-time load.

Share
Ankit Verma

Ankit Verma

Software developer at 3EA Limited. I build Laravel and React products, run the infrastructure behind them, and keep releases shipping.

More about me →

Read more posts

More write-ups on deployment, infrastructure, real-time systems, and shipping web products.

All articles