WebSockets at the OS Level: File Descriptors, Epoll, Buffers, and Kernel Tuning
When software engineers talk about WebSockets, the conversation usually focuses on client-side APIs (new WebSocket(url)), backend message handlers, or high-level Pub/Sub abstractions. We treat connections as lightweight objects in our code that magically stay alive and receive real-time updates.
But what actually happens underneath your application runtime? What is the Operating System kernel doing when your server maintains 100,000 or 1,000,000 concurrent WebSocket connections?
In this article, we are stepping away from high-level application frameworks to explore WebSockets at the OS level. We will inspect how Linux manages persistent TCP sockets, how event demultiplexing like epoll enables high concurrency, how kernel socket buffers consume system RAM, and how sysctl kernel tuning prevents your real-time infrastructure from falling over under load.
Understanding these OS-level mechanics changes how you architect, debug, and scale real-time applications.

