Backend Development 7 min read

Youzan ID Generator Multi-Room Solution

Youzan redesigned its ID generator to run independent March instances per room, sharing a single etcd cluster but allocating distinct, non‑overlapping ID ranges via boundary, lower, and upper parameters, enabling room‑level high availability, horizontal scaling, and zero‑downtime migration with automated tooling.

Youzan Coder
Youzan Coder
Youzan Coder
Youzan ID Generator Multi-Room Solution

The article discusses Youzan's ID generator (发号器) and its evolution to support multi-room deployments.

Initially, the ID generator relied on a single active‑primary March service with etcd for persistence, which caused issues in multi‑room setups: lack of room‑level high availability, excessive cross‑room traffic, limited horizontal scaling, and complex cluster resharding requiring downtime.

To address these problems, the team redesigned the architecture so that each room runs its own March instances, sharing the same etcd cluster but with isolated ID allocation ranges.

The solution introduces three configuration parameters for each room: boundary , lower , and upper . IDs are generated as id mod boundary and must fall within the room‑specific interval [ lower , upper ).

To guarantee non‑overlapping ranges between rooms, the following constraints must hold:

boundary1 == boundary2
lower1 != lower2
0 <= lower1 < upper1 <= lower2 < upper2 <= boundary

From these constraints it follows that id1 mod boundary ≠ id2 mod boundary , ensuring globally unique IDs.

An example configuration for two rooms is shown:

// Room 1
{
  "boundary": 100,
  "lower": 0,
  "upper": 50
}
// Room 2
{
  "boundary": 100,
  "lower": 50,
  "upper": 100
}

With this setup, Room 1 generates IDs 0‑49, 100‑149, 200‑249, … while Room 2 generates 50‑99, 150‑199, 250‑299, …

The article also describes how to extend or migrate the system without downtime: build a new cluster, configure ID ranges on both old and new clusters satisfying the constraints, set initial values, and then switch traffic. Migration can be performed by retracting ranges from one cluster and expanding them on another.

Finally, the authors emphasize the need for automation, compatibility with existing features, and operational simplicity, noting that they built an internal console to enforce constraints and execute steps.

backendarchitecturescalabilitydistributed systemetcdID Generatormulti-room
Youzan Coder
Written by

Youzan Coder

Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.

0 followers
Reader feedback

How this landed with the community

login 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.