Choosing the Right Distributed ID Strategy: UUID, DB, Redis, Snowflake Explained

Distributed ID systems must be globally unique, incremental, highly available, and secure; this article compares common generation methods—including UUID, database auto‑increment, Redis atomic counters, and the Snowflake algorithm—detailing their advantages, drawbacks, and suitable use‑cases for modern high‑throughput services.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Choosing the Right Distributed ID Strategy: UUID, DB, Redis, Snowflake Explained

Characteristics of Distributed IDs

Globally unique – no duplicate IDs.

Incremental – benefits relational DB index performance.

Highly available – must handle high request pressure.

Security – avoid predictable patterns.

Generation Schemes

UUID

The core idea combines the machine's MAC address, current timestamp, and a random number.

Advantages:

Very high performance, generated locally without network overhead.

Simple generation, no high‑availability risk.

Good security due to low readability and lack of pattern.

Disadvantages:

Lengthy, not easy to store.

Potential MAC address leakage.

Unordered, which harms MySQL InnoDB index performance.

Database

Uses the auto_increment feature of databases such as MySQL auto_increment.

Advantages:

Simple, leverages built‑in database functionality.

Absolutely ordered.

Disadvantages:

Risk of duplicate IDs during master‑slave switch.

Requires special measures to ensure high availability.

Generation speed limited by database performance; scaling incurs high cost.

Redis

Redis provides atomic increment commands that guarantee uniqueness and order.

Advantages:

Simple, self‑contained capability.

Excellent performance under high concurrency, better than databases.

Lower maintenance cost than databases.

Disadvantages:

Potential duplicate IDs during master‑slave failover.

High availability must be specially ensured.

Snowflake Algorithm

Assigns a unique identifier to each machine and composes a global unique ID using the structure:

Timestamp + Machine ID + Auto‑increment sequence

Timestamp occupies high bits, sequence low bits, ensuring monotonic increase.

Advantages:

High generation performance.

Flexible bit allocation to suit business needs.

Disadvantages:

Strong dependency on machine clock; clock rollback can cause service anomalies.

Summary

Different schemes have distinct characteristics; choose the one that fits your scenario.

For example, Meituan early used multiple forms: DB auto‑increment, Redis generators, and UUIDs. Later they released a Snowflake‑like service called Leaf with a QPS of about 50 k/s.

Project address: https://github.com/Meituan-Dianping/Leaf

Other references:

https://github.com/hengyunabc/redis-id-generator

https://github.com/baidu/uid-generator

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.

UUIDSnowflakeDistributed IDdatabase auto-increment
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

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.