ULID Generator
Generate Universally Unique Lexicographically Sortable Identifiers
ULID Generator
Generate Universally Unique Lexicographically Sortable Identifiers
About ULID Generator
Generate Universally Unique Lexicographically Sortable Identifiers (ULID) for modern applications. ULID combines the uniqueness of UUIDs with lexicographic sortability and improved performance characteristics.
- 128-bit compatibility with UUID
- Lexicographically sortable by timestamp
- Canonically encoded as 26-character strings
- Case insensitive and URL safe
- Monotonic sort order within same millisecond
How to Use ULID Generator
- Generate Single ULID - Click generate to create one unique identifier
- Bulk Generation - Specify quantity for multiple ULIDs at once
- Custom Timestamp - Optionally specify a custom timestamp
- Copy Results - Easily copy generated ULIDs to clipboard
- Validate Format - Verify existing ULID format and structure
Advertisement
Frequently Asked Questions
What is a ULID?
ULID (Universally Unique Lexicographically Sortable Identifier) is a 128-bit identifier that combines timestamp and randomness. It's sortable by creation time and provides better performance than traditional UUIDs for database indexing.
How does ULID compare to UUID?
ULIDs are lexicographically sortable, more compact when encoded, and provide better database performance. They're 26 characters long (vs 36 for UUID) and naturally ordered by creation time.
Are ULIDs truly unique?
Yes, ULIDs provide the same uniqueness guarantees as UUIDs. They use 48-bit timestamp and 80-bit randomness, ensuring virtually zero collision probability across distributed systems.
What is the ULID format?
ULIDs are encoded as 26-character strings using Crockford's Base32 encoding. Format: TTTTTTTTTTRRRRRRRRRRRRRRR where T=timestamp, R=randomness. Example: 01AN4Z07BY79KA1307SR9X4MV3
Can ULIDs be used as database primary keys?
Yes, ULIDs are excellent database primary keys. Their lexicographic sorting improves B-tree index performance, reduces page splits, and provides natural chronological ordering without additional timestamp columns.
Common Use Cases
- Database primary keys and indexes
- Distributed system identifiers
- Event sourcing and logging
- API request/response tracking
- File and document naming
- Session and transaction IDs
- Microservice correlation IDs
- Time-series data organization
Sponsored Content
Technical Specifications
ULID Structure:
- Total Length: 128 bits (same as UUID)
- Timestamp: 48 bits (Unix timestamp in milliseconds)
- Randomness: 80 bits (cryptographically strong random data)
- Encoding: Crockford Base32 (26 characters)
- Character Set: 0123456789ABCDEFGHJKMNPQRSTVWXYZ
ULID vs UUID Comparison
| Feature | ULID | UUID v4 | UUID v1 |
|---|---|---|---|
| Length | 26 chars | 36 chars | 36 chars |
| Sortable | ✅ Yes | ❌ No | ⚠️ Partially |
| URL Safe | ✅ Yes | ❌ No | ❌ No |
| Case Insensitive | ✅ Yes | ❌ No | ❌ No |
| Timestamp Embedded | ✅ Yes | ❌ No | ✅ Yes |
Programming Examples
JavaScript (Node.js):
const { ulid } = require('ulid');
// Generate a new ULID
const id = ulid();
console.log(id); // 01AN4Z07BY79KA1307SR9X4MV3
// Generate ULID with custom timestamp
const customTime = Date.now();
const idWithTime = ulid(customTime);
console.log(idWithTime);
// Validate ULID format
function isValidULID(id) {
const ulidRegex = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
return ulidRegex.test(id);
}
// Extract timestamp from ULID
function getULIDTimestamp(ulid) {
const timestampPart = ulid.substring(0, 10);
const base32Decode = (str) => {
const alphabet = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
let result = 0;
for (let char of str) {
result = result * 32 + alphabet.indexOf(char);
}
return result;
};
return base32Decode(timestampPart);
}
Python:
from ulid import ULID
import time
import re
# Generate a new ULID
ulid_obj = ULID()
print(str(ulid_obj)) # 01AN4Z07BY79KA1307SR9X4MV3
# Generate ULID from timestamp
timestamp = int(time.time() * 1000)
ulid_from_time = ULID.from_timestamp(timestamp)
print(str(ulid_from_time))
# Parse existing ULID
existing_ulid = ULID.from_str('01AN4Z07BY79KA1307SR9X4MV3')
print(f"Timestamp: {existing_ulid.timestamp}")
print(f"Randomness: {existing_ulid.randomness}")
# Validate ULID format
def is_valid_ulid(ulid_str):
pattern = r'^[0-7][0-9A-HJKMNP-TV-Z]{25}$'
return re.match(pattern, ulid_str) is not None
# Generate multiple ULIDs
ulids = [str(ULID()) for _ in range(5)]
print("Generated ULIDs:", ulids)
print("Are sorted:", ulids == sorted(ulids))
Advertisement
