Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ID Types Comparison

A comprehensive comparison of all ID types supported by idt.

Quick Reference

TypeBitsSortableTimestampRandom BitsString Length
UUIDv1128NoYes~1436
UUIDv3128NoNo036
UUIDv4128NoNo12236
UUIDv5128NoNo036
UUIDv6128YesYes~6236
UUIDv7128YesYes6236
ULID128YesYes8026
NanoID~126NoNo~12621
Snowflake64YesYes0~19
KSUID160YesYes12827
ObjectId96PartialYes~4024
XID96YesYes~4020
TSID64YesYes~2213-17

Detailed Comparison

Timestamp Precision

TypePrecisionEpoch
UUIDv1100 nanosecondsOctober 15, 1582
UUIDv6100 nanosecondsOctober 15, 1582
UUIDv7MillisecondsUnix epoch (1970)
ULIDMillisecondsUnix epoch (1970)
SnowflakeMillisecondsCustom (e.g., 2010, 2015)
KSUIDSecondsMay 13, 2014
ObjectIdSecondsUnix epoch (1970)
XIDSecondsUnix epoch (1970)
TSIDMillisecondsUnix epoch (1970)

Collision Resistance

TypeSame MillisecondDifferent NodesNotes
UUIDv4ExcellentExcellent122 random bits
UUIDv7GoodExcellent62 random bits + timestamp
ULIDExcellentExcellentMonotonic + 80 random bits
NanoIDExcellentExcellent~126 random bits
SnowflakeLimitedRequires coordination4096/ms per worker

Encoding

TypeEncodingCase SensitiveAlphabet
UUIDHexadecimalNo0-9, a-f
ULIDCrockford Base32No0-9, A-Z (excluding I, L, O, U)
NanoIDCustom (default URL-safe)YesA-Z, a-z, 0-9, -, _
SnowflakeDecimalN/A0-9
KSUIDBase62Yes0-9, A-Z, a-z
ObjectIdHexadecimalNo0-9, a-f
XIDBase32No0-9, a-v

Use Case Recommendations

Database Primary Keys

RequirementRecommended Type
UUID compatibility requiredUUIDv7
Compact storageULID or Snowflake
Time-sortable queriesUUIDv7, ULID, or Snowflake
Maximum randomnessUUIDv4
64-bit integer columnSnowflake or TSID

Distributed Systems

RequirementRecommended Type
No coordination neededUUIDv7, ULID, UUIDv4
Very high throughputSnowflake
Cross-datacenterUUIDv7 or ULID
Compact wire formatSnowflake (64-bit)

User-Facing IDs

RequirementRecommended Type
Short URL slugsNanoID (custom length)
Readable codesNanoID (custom alphabet)
Compact but sortableULID
Standard formatUUID (canonical)

Security-Sensitive

RequirementRecommended Type
Non-sequentialUUIDv4 or NanoID
Hide creation timeUUIDv4 or NanoID
Cryptographic randomnessUUIDv4 or NanoID

Format Conversion Compatibility

Since ULID and UUID are both 128-bit, they can be converted between each other:

# ULID to UUID hex
idt convert 01ARZ3NDEKTSV4RRFFQ69G5FAV -f hex
# Can be stored in UUID column

# UUID to various formats
idt convert 550e8400-e29b-41d4-a716-446655440000 -f base64

Storage Size Comparison

TypeBinary (bytes)String (chars)Typical DB Type
UUID1636UUID, CHAR(36), BINARY(16)
ULID1626CHAR(26), BINARY(16)
NanoID~1621VARCHAR(21+)
Snowflake8~19BIGINT
ObjectId1224ObjectId, CHAR(24)

Feature Matrix

FeatureUUIDv4UUIDv7ULIDNanoIDSnowflake
Time-sortable-YesYes-Yes
Extract timestamp-YesYes-Yes
URL-safe--YesYesYes
Fits in 64-bit----Yes
No coordinationYesYesYesYes-
Customizable---YesYes
RFC standardYesYes---
Widely supportedYesGrowingGrowingGrowingYes