Hermes: A Lightweight, High‑Reliability Mobile Message Push System Based on MQTT and Protocol Buffers
The article presents Hermes, a lightweight and highly reliable mobile push system built with MQTT and Protocol Buffers, detailing its background, technology selection, architecture, heartbeat and reconnection strategies, future optimizations, and practical results that achieve over 99% message delivery rate.
Introduction Hermes (the messenger system) is a lightweight, high‑reliability mobile push solution developed by the financial wireless team, using MQTT and Protocol Buffers to achieve real‑time server‑to‑client message delivery with minimal resource consumption.
Background The 58 financial business required real‑time data updates on mobile clients without the overhead of polling, leading to the decision to implement a custom long‑connection push system named Hermes.
Technical Selection After evaluating third‑party push SDKs (Jiguang, Getui, Baidu, Tencent Xiong), the team concluded that none met the strict timeliness and delivery‑rate requirements, prompting a self‑built solution based on MQTT for transport and Protocol Buffers for serialization.
MQTT MQTT is a lightweight publish/subscribe protocol designed for low‑bandwidth, high‑reliability scenarios such as IoT. Its features—small packet size, QoS levels (0, 1, 2), and decoupled messaging—make it suitable for the Hermes system’s long‑connection push needs.
Protocol Buffers Protocol Buffers provide compact, cross‑language binary serialization, reducing payload size compared to JSON or XML and simplifying integration across platforms.
Implementation Overview The system architecture consists of four layers: business, application, transport, and network. The business layer handles data format conversion, duplicate/loss detection, short‑term storage, and statistics. The application layer implements heartbeat, reconnection, and connection‑state management. The transport layer manages socket operations, while the network layer provides the underlying TCP connection.
Heartbeat Strategy Heartbeat packets are sent at intervals shorter than carrier NAT timeout (typically 120 seconds) to keep the long‑connection alive, detect NAT expiration, and confirm both client and server liveness.
Reconnection Mechanism Upon disconnection, the client retries with a random delay up to 15 seconds, limiting the number of attempts to six to avoid reconnection storms and reduce battery and data consumption.
Future Optimizations Planned improvements include push delivery when the app is killed (via APNS on iOS) and an adaptive heartbeat that adjusts interval based on network conditions.
Conclusion The Hermes system achieved over 99% message delivery rate and reliable timeliness in production, demonstrating the effectiveness of the MQTT + Protocol Buffers approach for mobile real‑time push scenarios.
References MQTT official documentation, Protocol Buffers homepage, MQTT‑Client open‑source library.
58 Tech
Official tech channel of 58, a platform for tech innovation, sharing, and communication.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.