How WeChat Guarantees Real‑Time, Lossless Messaging: Architecture & Sequence Mechanism

The article explains the evolution of WeChat’s message‑sending and receiving architecture, detailing the two‑stage flow from mobile client to server and back, the real‑time delivery and loss‑prevention requirements, and the sequence‑based mechanism that ensures messages are delivered without loss even under weak network conditions.

dbaplus Community
dbaplus Community
dbaplus Community
How WeChat Guarantees Real‑Time, Lossless Messaging: Architecture & Sequence Mechanism

Background

WeChat, with a daily active user base of 1.34 billion in 2023, originated from the QQMail team and initially inherited an email‑style storage‑forward model for message handling. The core requirements for an instant‑messaging platform are (1) near‑real‑time delivery and (2) no message loss.

Message Sending Architecture

The sending process is divided into two main parts. First, the mobile client (Phone A) sends a request to the access layer ConnectSvr, which forwards it to the logic layer SendSvr. After anti‑spam checks, blacklist filtering, and other business logic, SendSvr stores the message in MsgStore. Second, the server notifies the recipient (Phone B) via a push flow: SendSvr triggers PushSvr, which either pushes through the long‑connection ConnectSvr (steps 5.1‑6) or falls back to platform‑specific push services such as APNs, WPPush, or BBPush (step 5.2) when the long‑connection is unavailable.

WeChat message sending flow diagram
WeChat message sending flow diagram

Message Receiving Architecture

When Phone B receives the push notification, it initiates a three‑step retrieval process: (1) request to ConnectSvr, (2) forwarding to ReceiveSvr, and (3) fetching the pending messages from MsgStore. This flow ensures that the recipient can obtain the message within roughly 100 ms after the sender’s request.

WeChat message receiving flow diagram
WeChat message receiving flow diagram

Sequence‑Based Loss‑Prevention Mechanism

To avoid message loss, each user is allocated a 32‑bit sequence space (≈4.2 billion values). Every outgoing message receives a unique, monotonically increasing sequence number. The server records the highest sequence assigned, while the client stores the highest sequence it has successfully processed.

The client periodically reports its current sequence ( Seq_cli) to the server. The server compares this with its own highest sequence ( Seq_svr) and delivers any missing messages in the range (Seq_cli + 1) … Seq_svr. This incremental delivery works even if acknowledgments are lost or the network is weak, because the client can re‑request the missing range after a timeout.

When a user logs in from multiple devices, each device reports its own Seq_cli. The server’s stored maximum sequence ensures that already‑confirmed messages are not resent, while unconfirmed messages are still delivered to any device that needs them.

Sequence comparison illustration
Sequence comparison illustration
Message retrieval across devices
Message retrieval across devices

Conclusion

The described architecture satisfies WeChat’s two fundamental messaging requirements: near‑real‑time delivery and zero loss. Although the system has evolved since its 2014 version, the core principles of layered servers, push fallback mechanisms, and sequence‑based synchronization remain valuable references for designing large‑scale instant‑messaging services.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Sequence MechanismWeChatReal-time DeliveryMessaging Architecture
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.