Five Distributed Global Unique ID Generation Schemes and Their Comparison
This article explains the concept of distributed global unique identifiers, outlines four essential characteristics of such IDs, and provides a detailed comparison of five generation schemes—UUID, database‑generated IDs, Redis, Zookeeper, and Snowflake—highlighting their advantages, drawbacks, and suitable use cases.
In complex distributed systems, uniquely identifying large volumes of data and messages is crucial, especially for domains like finance, e‑commerce, and payment platforms where auto‑increment IDs are insufficient.
Four Key Characteristics of Distributed Unique IDs
1. Global uniqueness – IDs must never repeat.
2. Trend‑increasing – Ordered primary keys improve write performance in B‑tree indexes.
3. Monotonic increase – Each subsequent ID must be larger, useful for versioning and ordered messaging.
4. Information security – Non‑sequential IDs prevent easy enumeration and protect business metrics.
High availability of the ID generation service is also critical to avoid system‑wide failures.
Implementation Schemes for Distributed Unique IDs
1. UUID
UUIDs are 128‑bit identifiers formatted as 8‑4‑4‑4‑12 hexadecimal characters (e.g., 550e8400‑e29b‑41d4‑a716‑446655440000). They are generated locally without network latency.
Advantages: Very high performance, no network dependency.
Disadvantages: Large storage footprint, potential MAC address leakage, and suboptimal as primary keys in many databases.
2. Database‑Generated IDs
Using MySQL’s auto_increment_increment and auto_increment_offset to produce globally unique, monotonically increasing IDs.
Advantages: Simple to implement, leverages existing DB infrastructure, provides ordered IDs.
Disadvantages: Strong DB dependency—DB failures can cripple the system; scalability limited by a single DB’s read/write capacity.
3. Redis‑Generated IDs
Redis’s atomic commands INCR and INCRBY can generate IDs, often used for daily sequential numbers like order IDs.
Advantages: Independent of DB, high performance, naturally ordered numeric IDs.
Disadvantages: Requires introducing Redis if not already present, adds configuration and development overhead.
4. Zookeeper‑Generated IDs
Zookeeper can issue sequential numbers via znode version numbers (32‑bit or 64‑bit). However, it involves multi‑step API calls and may need distributed locks under high contention.
Disadvantages: Dependency on Zookeeper and lower performance in high‑concurrency scenarios.
5. Snowflake Algorithm
Snowflake splits a 64‑bit number into timestamp, machine ID, and sequence fields, enabling trend‑increasing, high‑throughput ID generation (up to ~4 million IDs per second).
Advantages: Timestamp‑based ordering, no DB dependency, highly configurable bit allocation.
Disadvantages: Relies on accurate system clocks; clock rollback can cause duplicate IDs or service disruption.
Overall, selecting an ID generation strategy depends on factors such as performance requirements, operational complexity, and security considerations.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
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.