No Coordination
UUID, ULID generate unique IDs without central coordination. Snowflake needs machine ID assignment but no runtime coordination.
In distributed systems, we need to generate unique identifiers for:
The Challenge: How do we generate unique IDs across multiple nodes without coordination? How do we ensure no collisions? How do we make IDs sortable and efficient?
Sequential IDs (like database auto-increment) require coordination:
Problems:
Not suitable for distributed systems!
UUID is a 128-bit identifier that’s globally unique without coordination.
UUID v4 uses 122 random bits (4 bits for version/variant).
Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
4 = version 4y = variant (8, 9, A, or B)Characteristics:
Use Cases:
UUID v7 uses timestamp + random bits (time-ordered).
Format: xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx
7 = version 7Characteristics:
Use Cases:
Snowflake is Twitter’s ID generation algorithm. Generates 64-bit time-ordered IDs.
64-bit ID:├─ 41 bits: Timestamp (milliseconds since epoch)├─ 10 bits: Machine ID (0-1023 machines)└─ 12 bits: Sequence number (0-4095 per millisecond)How It Works:
Performance:
Requirements:
ULID combines timestamp and randomness in a lexicographically sortable format.
128-bit ULID:├─ 48 bits: Timestamp (milliseconds since 1970-01-01)└─ 80 bits: RandomFormat: 01ARZ3NDEKTSV4RRFFQ69G5FAV (Base32 encoded, 26 characters)
Characteristics:
Use Cases:
| Feature | UUID v4 | UUID v7 | Snowflake | ULID |
|---|---|---|---|---|
| Size | 128 bits | 128 bits | 64 bits | 128 bits |
| Sortable | No | Yes | Yes | Yes |
| Coordination | None | None | Machine ID needed | None |
| Performance | Fast | Fast | Very fast | Fast |
| Collision Risk | Very low | Very low | Very low | Very low |
| Database Indexing | Poor (random) | Good (time-ordered) | Excellent | Excellent |
Use UUID v4 when:
Use UUID v7 when:
Use Snowflake when:
Use ULID when:
No Coordination
UUID, ULID generate unique IDs without central coordination. Snowflake needs machine ID assignment but no runtime coordination.
Time-Ordered
UUID v7, Snowflake, ULID are time-ordered. Improves database indexing performance compared to random UUID v4.
Collision Probability
All algorithms have extremely low collision probability. UUID v4: ~5×10^-37 for single collision. Practical systems don’t worry about collisions.
Choose Wisely
Consider size, sortability, coordination needs, and database indexing when choosing ID generation strategy.