Backend Development 14 min read

Design and Implementation of a High‑Performance Global Unique ID Generation Algorithm (Mist) and Service (Medis)

This article analyses the limitations of existing global unique ID solutions such as Snowflake, presents the design of a new high‑performance, time‑independent Mist algorithm with extended lifespan, and describes its practical Redis‑backed service Medis, including performance benchmarks and architectural considerations.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
Design and Implementation of a High‑Performance Global Unique ID Generation Algorithm (Mist) and Service (Medis)

Global unique identifiers are essential infrastructure for distributed systems and order‑centric applications. The article first reviews the requirements for such IDs—global uniqueness, monotonic increase, trend increase, and security—citing examples from Baidu UIDGenerator, Meituan Leaf, and Tencent Seqsvr.

It then examines common ID generation methods, highlighting the drawbacks of UUID/GUID, database auto‑increment, and Redis‑based timestamp seeds, before introducing Twitter's Snowflake algorithm, which uses a 64‑bit structure (1 sign bit, 41‑bit timestamp, 10‑bit machine ID, 12‑bit sequence).

Snowflake's reliance on system time leads to issues such as clock rollback causing duplicate IDs and limited per‑millisecond throughput. To overcome these, the author proposes the Mist algorithm, which replaces the timestamp with a simple auto‑increment counter ( 1,2,3,4,5,... ) and reduces the machine‑ID and sequence bits to 8 each, while expanding the middle segment to 47 bits, yielding a theoretical lifespan of over 385 years.

The Mist design also uses random values for the lower segments to improve security, and its implementation in Go avoids time‑stamp calls, achieving nanosecond‑level latency. Sample Go code is provided in the original source.

To make the algorithm usable, the author builds Medis, a Redis‑backed service that pre‑fetches ID blocks using channels, pipelines, and Lrange/Ltrim operations, achieving around 25 000 IDs per second in benchmarks. Architectural diagrams illustrate the service startup and request flow.

Finally, the article discusses high‑availability considerations, CAP trade‑offs, and options for scaling Medis across multiple nodes using KV stores like etcd or Zookeeper, while warning about the inherent performance limits of distributed KV solutions.

Distributed SystemsPerformancegolangRedisSnowflakeglobal unique ID
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

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.