Engineering the future: how mezon-sock-c is built for 1M + CCU

๐๐๐๐๐๐๐๐๐๐๐๐ ๐๐๐ ๐ ๐๐๐๐๐: ๐๐๐ ๐๐๐๐๐-๐๐๐๐-๐ ๐๐ ๐๐๐๐๐ ๐ ๐๐ ๐๐+ ๐๐๐๐
When we set out to build the next generation of our socket gateway, we didn't just want it to work - we wanted it to be unbreakable . To hit 1 Million Concurrent Users (CCU) on a single cluster, standard high-level languages weren't enough. We went "to the metal" with C and a modern asynchronous architecture.
1๏ธโฃ ๐ข๐จ_๐ฎ๐ซ๐ข๐ง๐ : ๐๐ก๐ ๐๐๐ซ๐ง๐๐ฅ ๐๐๐ฏ๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง ๐ง
We ditched the overhead of traditional epoll. By using io_uring , we minimize expensive syscalls and context switches. Our worker threads "talk" to the Linux kernel via shared memory rings, allowing us to process thousands of I/O events per microsecond with near-zero CPU waste.
2๏ธโฃ ๐๐ก๐๐ซ๐๐๐ ๐๐ก๐ซ๐๐๐-๐๐๐๐ ๐๐ซ๐๐๐ค๐๐ซ ๐งฉ
Managing 1M user states is a locking nightmare. We solved this by sharding our Session Registry and Presence Tracker across 1024+ internal buckets. This allows our 8-core (or 64-core!) workers to update user status and room memberships simultaneously without fighting over a single global lock.
3๏ธโฃ ๐๐๐ซ๐จ-๐๐จ๐ฉ๐ฒ ๐๐ซ๐จ๐ญ๐จ๐๐ฎ๐ & ๐๐ฎ๐ฌ๐ญ๐จ๐ฆ ๐๐ฎ๐๐๐๐ซ๐ข๐ง๐ โก
Data doesn't move unless it has to. By using Protobuf-C and mimalloc (Microsoft's high-performance allocator), weโve eliminated heap fragmentation. We use a reference-counted broadcast system, meaning a single 1KB message is packed once and referenced across thousands of client write-queues.
4๏ธโฃ ๐๐จ๐ซ๐ข๐ง๐ ๐๐๐ & ๐๐๐๐ฎ๐ซ๐ ๐๐๐ง๐๐ฌ๐ก๐๐ค๐๐ฌ ๐
Security shouldn't be a bottleneck. By integrating Googleโs BoringSSL , we perform high-speed TLS handshakes and JWT HS256 verification in the same event loop. Weโve even optimized the JWT decoding to use constant-time comparisons to prevent timing attacks while maintaining massive throughput.
5๏ธโฃ ๐๐ก๐ "๐๐จ๐ฆ๐ ๐๐ก๐๐ซ๐" ๐๐ฉ๐ญ๐ข๐ฆ๐ข๐ณ๐๐ญ๐ข๐จ๐ง ๐
One of our biggest wins: The Home Shard Principle . We map a sessionโs entire membership list to a specific shard based on their ID. This turned the "Disconnect All" operation from a slow $O(N)$ brute-force search into a lightning-fast $O(1)$ lookup.
๐๐ก๐ ๐๐๐ฌ๐ฎ๐ฅ๐ญ?
Low latency, predictable tail-latencies (p99), and a memory footprint so small it makes VM-based languages look like dinosaurs. ๐ฆ
We're pushing the boundaries of what a real-time gateway can do. Stay tuned for the benchmark reports!
------------------------------------------------
MEZON - YOUR CLAN, YOUR WORLD!
A product proudly developed by the engineers at NCCPLUS.
๐ Website: https://mezon.ai/
๐ง Email: hello@mezon.vn
๐ Hotline: 024.6687.4606
๐ฒ Available on App Store & Google Play