Executive Summary: To scale WebSockets to thousands of concurrent users, I architected an in-memory Golang Hub-and-Spoke model, while Vue.js 3 manages client-side reactive state synchronization. This approach entirely eliminates expensive REST polling and exponentially reduces database connection load.
Building a real-time web application that perfectly synchronizes state across thousands of concurrent clients is one of the toughest challenges in modern software engineering. 'Just use WebSockets' is terrible advice if you don't understand how to scale the connection layer.
Why REST Polling Fails
In the early iterations of most B2B dashboards (including the RTIMS project I worked on), developers rely on client-side polling. A React or Vue app is set to hit a REST endpoint every 5 seconds. For 100 users, this is 20 requests per second. Easy.
However, scale that to 5,000 active clients, and you're suddenly dealing with 1,000 API requests arriving every single second. Every request has to pass through HTTP middleware layers, framework deserialization, and query PostgreSQL. This hammers the database and exhausts server memory incredibly fast, even if no actual data has changed.
Enter Go (Golang) and the Hub Architecture
Go was built from the ground up for concurrency. Unlike Node.js which is fundamentally single-threaded, or PHP which spins up a process per request, Go can launch tens of thousands of goroutines with minimal memory overhead (around 2KB per goroutine).
We utilized a standard Hub-and-Spoke pattern. A central goroutine acts as the 'Hub', maintaining a thread-safe registry of all connected clients using a sync.Mutex. When a mutation occurs via an external system, a JSON payload is pushed to the Hub's broadcast channel. The Hub then iterates over the clients, fanning the message out to individual client goroutines, which push the data down the underlying TCP socket.
Client State Management with Vue.js 3
Pushing the data from the server is only half the battle. Once this relentless stream of JSON payloads hits the frontend, your UI layer can choke if not managed correctly. This is where Vue.js 3's Composition API (with its Proxy-based reactivity) shines.
Instead of thrashing the entire DOM structure every time a WebSocket update arrives (which would cause severe UI lag), we use Pinia stores with reactive state injection. When the WebSocket receives a payload of type 'INVENTORY_UPDATE', it directly mutates the specific object within the Pinia array. Vue's surgical reactivity ensures that only the exact table row undergoing an update will re-render, while the thousands of other DOM nodes remain completely static.
Conclusion: Don't Just Throw Sockets at the Problem
While WebSockets deliver a seemingly magical user experience, they introduce stateful complexity to your backend. Marrying the raw thread efficiency of Go with the intelligent reactivity system of Vue.js allows you to build true, living enterprise applications without melting your servers.