How WeChat’s SeqSvr Generates Trillions of Sequence Numbers Daily

This article explains the design and evolution of WeChat's high‑availability seqsvr service, which provides per‑user 64‑bit sequence numbers for data synchronization, handling trillions of requests with millisecond latency through pre‑allocation, section sharing, and layered storage architecture.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
How WeChat’s SeqSvr Generates Trillions of Sequence Numbers Daily

Background

WeChat assigns a unique, monotonically increasing 64‑bit sequence number to every piece of data that needs to be synchronized with the client. During sync, the client sends its highest known version; the server computes the incremental data to return, ensuring reliable and efficient synchronization.

Instead of using optimistic locks, a dedicated service called seqsvr generates these sequences. Each user has an independent 64‑bit sequence space, avoiding global contention and simplifying update detection across different data types.

Sequences have two basic properties:

Monotonically increasing 64‑bit integer.

Each user owns an independent 64‑bit sequence space.

For example, if user A currently holds sequence 100, the next allocation may be 101 or 110, but it will always be greater than 100. User B’s sequence space is independent, so allocations to user A never affect user B.

Architecture Prototype

The simplest model treats seqsvr as a massive 64‑bit array where each user occupies an 8‑byte slot storing the last allocated sequence ( cur_seq). To allocate a new sequence, the service increments cur_seq and returns the value.

SeqSvr allocation example
SeqSvr allocation example

Pre‑allocation Layer

To handle billions of daily requests, seqsvr stores the current sequence ( cur_seq) and an allocation ceiling ( max_seq) in memory. When cur_seq exceeds max_seq, the ceiling is increased by a step (e.g., 10,000) and persisted. On restart, the persisted max_seq is loaded into cur_seq. This reduces disk I/O from ~10⁷ QPS to ~10³ QPS.

Pre‑allocation example
Pre‑allocation example

Section‑Shared Storage

Loading all max_seq values (32 GB for 2³² users) is impractical. Seqsvr groups adjacent user IDs into sections; users in the same section share a single max_seq. This reduces the persisted data to a few hundred kilobytes.

Section sharing diagram
Section sharing diagram

Engineering Implementation

The production system splits the storage and cache layers into two modules:

StoreSvr : Handles persistent storage with multi‑node NRW (non‑volatile write) to guarantee durability.

AllocSvr : Acts as an in‑memory cache, deployed on many machines, each responsible for a subset of sections, distributing the massive request load.

Furthermore, the system is divided into sets based on UID ranges; each set contains an independent StoreSvr + AllocSvr pair, providing disaster isolation—failure of one set affects only its users.

Prototype architecture diagram
Prototype architecture diagram

Conclusion

Seqsvr’s simple yet elegant layered design has reliably supported WeChat’s rapid growth for five years, handling ever‑increasing traffic while maintaining strict monotonicity and high availability. Future articles will discuss the evolution of its disaster‑recovery strategies.

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.

Distributed SystemsScalabilitysequence generation
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

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.