How WeChat Scales: Backend Architecture for Ultra‑Low Latency Messaging
The article outlines WeChat’s backend design that achieves seamless, low‑latency messaging through a minimalist sync protocol, efficient notification mechanisms, a three‑tier RPC framework, user‑level thread concurrency, and globally distributed IDC architecture ensuring high availability and eventual consistency.
Note: Company lecture notes, not guaranteed accurate.
Problem
Extreme business features
Smooth message sending and receiving
Timely notifications
Power saving
Bandwidth saving
Thin client
Difficult backend‑terminal synchronization
Synchronizing diverse data: account info, contacts, messages, moments, etc.
Timely notification and sync
Reliable sync over mobile networks
Saving bandwidth and power
Solution
Minimalist sync protocol
The backend and terminal only need to exchange a single number; the backend can infer all missing data on the terminal.
Change sequence number / version number:
Efficient notification mechanism
iOS Apple Push Network Service
Android and others – long connections
GPRS/EDGE signaling storm optimization
Adaptive heartbeat interval adjustment
Three‑layer backend architecture
Unified RPC framework
Generate server and client code from Protocol Buffer definitions
Hide network details
Rich features
High‑concurrency coroutine RPC
Server‑side synchronous call model is easier to learn, use, and debug than an asynchronous model, but a single server can only support a limited number of processes and threads.
RPC based on user‑level threads (coroutines)
A single machine can support tens of thousands to a hundred thousand user‑level threads, limited only by CPU and memory.
Improves concurrency and performance.
Implementation of user‑level thread RPC
Based on makecontext / getcontext / swapcontext Hook network calls: read/write/epoll
User‑level thread scheduling
Proximity access
IDC proximity access
Network access near major carriers
CDN for image upload/download
Multiple IDC distribution improves user experience
Complex domestic network environment
Over 100 million overseas users
Each IDC provides full functionality and all required data
Each IDC holds both shared and independent data
IDC distributed data high‑reliability eventual consistency guarantee
Primary‑backup model for account and SNS data
Weakly real‑time cross‑IDC updates use a Zookeeper‑mediated primary‑backup task queue
Social graph cross‑IDC updates
Fault tolerance and disaster recovery mechanisms
Single IDC
High‑availability geographic disaster recovery
Source: http://blog.xiayf.cn/2013/10/23/learning-in-tencent-backend-arch-of-weixin/
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
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.
