Mobile Development 10 min read

How WeChat’s Mars Library Powers Reliable Mobile Networks

WeChat’s Mars library, a C++‑based cross‑platform network component used across Android, iOS, macOS, Windows and more, offers optimized signaling (STN), logging (XLOG), diagnostics (SDT) and core utilities, enabling reliable mobile connections and simplifying development, and will soon be open‑sourced.

WeChat Client Technology Team
WeChat Client Technology Team
WeChat Client Technology Team
How WeChat’s Mars Library Powers Reliable Mobile Networks

4G and the upcoming 5G era are rapidly evolving, but network libraries remain essential. Mars originated from WeChat’s need to handle mobile‑internet instability, incorporating extensive optimizations validated by long‑term use.

On December 9, InfoQ’s China Tech Open Day in Guangzhou featured senior WeChat engineer Zhou Zhijie presenting “WeChat Mars: Exploring High‑Quality Network Connections under Mobile Internet.” The event was free and open to interested participants.

Mars is an official WeChat terminal base component written in C++, platform‑agnostic and used in Android, iOS, macOS, Windows, and WP clients. It is being prepared for open‑source release and consists of four main parts:

COMM: foundational library offering sockets, threads, message queues, coroutines, and other basic tools.

XLOG: a universal logging module designed for mobile terminals, providing high‑performance, high‑availability, secure, and fault‑tolerant logging.

SDT: a network‑diagnostic module.

STN: the signaling transmission network, responsible for lightweight signaling channels between the client and server; it encapsulates WeChat’s extensive mobile‑network optimization experience.

STN is the core module.

Mars was created to address the challenges of maintaining consistent functionality across multiple platforms with billions of users. Divergent implementations made quality control difficult and hindered deep research, prompting the development of a cross‑platform foundation that has been refined within WeChat for years. Open‑sourcing aims to further improve the component and foster industry collaboration.

Most of WeChat’s network‑related features—text messages, voice messages, Moments, etc.—rely on Mars. Only a few services such as VOIP and WebView fall outside its scope. WeChat’s network services are divided into signaling (handled by STN) and data (handled by a separate CDN component not included in the open‑source list).

SDT provides basic detection capabilities that developers can combine as needed. Standard platform Reachability APIs are limited; SDT offers more comprehensive diagnostics tailored to WeChat’s stringent requirements.

STN abstracts WeChat’s usage model into a business‑agnostic network channel, applied across many Tencent internal applications. Unlike AFNetworking, Retrofit, or OkHttp, STN emphasizes mobile‑internet characteristics, incorporating custom DNS, disaster‑recovery design, load considerations, foreground/background handling, sleep mechanisms, and power‑saving strategies.

STN offers additional advantages:

Data monitoring: numerous callbacks enable developers to build analytics and monitoring tools based on network data.

Problem locating: extensive logging, combined with Mars’s XLOG, assists in pinpointing network issues at runtime.

Parameter configuration: many settings are exposed for developers to adjust according to their needs.

STN provides both long‑connection and short‑connection channels, allowing developers to focus on business logic while STN handles mobile‑internet challenges.

Cross‑Platform Component Development Experience

Cross‑platform components are typically written in C++ and compiled into binary libraries for each platform, then linked via the platform’s SDK. They are low‑level, platform‑agnostic, and UI‑independent, similar to game engines or databases.

Such components enable a single codebase to run everywhere, reducing development and maintenance effort—especially valuable as mobile teams grow and business scales.

The network layer has minimal coupling with system and UI, making it highly suitable for cross‑platform implementation.

WeChat’s Mars development emphasizes high availability, performance, low load, and disaster resilience. Challenges include handling API compatibility across platforms, accommodating platform‑specific features (e.g., sleep mechanisms), and designing simple, stable solutions without frequent architectural changes.

Stability and testing requirements are higher for cross‑platform components. WeChat employs platform‑specific testing tools and extensive automated tests to ensure robustness; crashes attributable to the component remain a small fraction of overall issues.

Mars will be open‑sourced soon, with ongoing maintenance from the WeChat team.

Reference links:

GMTC PPT: WeChat client strategies for weak networks – http://ppt.geekbang.org/slide/show/203

WeChat cross‑platform component Mars series (1) – High‑performance logging module XLOG – http://mp.weixin.qq.com/s/cnhuEodJGIbdodh0IxNeXQ

Cross-PlatformMobile NetworkingWeChatC++Network Library
WeChat Client Technology Team
Written by

WeChat Client Technology Team

Official account of the WeChat mobile client development team, sharing development experience, cutting‑edge tech, and little‑known stories across Android, iOS, macOS, Windows Phone, and Windows.

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.