ksuid.net

Which Unique ID Format Should I Use?

A practical guide to choosing the right identifier format for your project, with a decision matrix covering all 20+ formats on ksuid.net.

Decision Flowchart

Need RFC compliance?

UUID v4 or UUID v7

Need time-sorting for database performance?

UUID v7, ULID, KSUID, TSID, Snowflake

Need the shortest possible ID?

Sqids, TSID, XID, Nano ID

Need to fit in a 64-bit integer column?

Snowflake, TSID

Need maximum collision resistance?

UUID v4, KSUID, CUID2

Need anti-fingerprinting protection?

CUID2

Need minimal client-side bundle?

Nano ID

Decision Matrix

FormatBest ForTier
cuidLegacy apps already using CUID v1Legacy
cuid2Security-sensitive apps needing anti-fingerprintingRecommended
ksuidHigh-throughput event pipelines with second-level orderingSituational
nanoidClient-side apps where bundle size mattersRecommended
objectidMongoDB-native applicationsLegacy
pushidFirebase/real-time database applicationsSituational
scru128High-volume systems needing monotonic sortable IDsRecommended
shortidNone — deprecated, migrate to Nano IDLegacy
slugidURL-safe identifiers in task queuesLegacy
snowflake64-bit integer keys with extreme throughputSituational
sqidsObfuscating sequential numeric IDs in URLsSituational
short-uuidCompact display of existing UUIDsLegacy
timeflakeUUID-compatible time-sorted IDsRecommended
tsidCompact 64-bit time-sorted primary keysRecommended
ulidTime-sorted IDs with UUID-compatible storageRecommended
ulidxModern ULID with strict spec complianceRecommended
uniqidNone — use UUID v7 or TSID insteadLegacy
uuidRFC compliance and maximum ecosystem supportSituational
uuidv7New projects needing standards-compliant sortable IDsRecommended
xidCompact sortable IDs across Go/JS/Python ecosystemsSituational

Understanding the Tiers

Recommended

Strong defaults for new projects. These formats use cryptographic randomness, are actively maintained, and offer modern features like time-sorting or anti-fingerprinting.

Examples: UUID v7, ULID, CUID2, Nano ID, SCRU128, TSID, Timeflake

Situational

Solid choices for specific use cases but with trade-offs. They may lack cryptographic randomness, require coordination, or have a narrower ecosystem.

Examples: UUID v4, KSUID, Snowflake, XID, Sqids, Push ID

Legacy

Outdated or have known weaknesses. Avoid in new projects. If your existing system uses one, consider migrating when practical.

Examples: CUID v1, ShortId, ObjectId, Short-UUID, Slugid, Uniqid

Popular Comparisons

All Generators

Frequently Asked Questions

What is the best unique ID format for a new project?

For most new projects, UUID v7 is the best default choice. It combines the universal compatibility of the UUID format (128-bit, RFC 9562, native database support) with time-sorted ordering that dramatically improves database insert performance. If you need a more compact representation, ULID or TSID are excellent alternatives.

Should I use UUID v4 or UUID v7?

UUID v7 is the better choice for nearly all new systems. It offers the same format compatibility as UUID v4 but with time-sorted ordering that reduces B-tree index fragmentation and improves write throughput by 2-10x. UUID v4 remains appropriate only when you specifically need to avoid embedding any timestamp information in your identifiers.

What is the difference between Recommended, Situational, and Legacy tiers?

Recommended (green) formats are strong defaults for new projects — they use cryptographic randomness, have active maintenance, and offer modern features. Situational (orange) formats are solid choices for specific use cases but have trade-offs that make them less universal. Legacy (red) formats are outdated or have known weaknesses and should generally be avoided in new projects.

Which ID format is best for distributed microservices?

UUID v7, ULID, and CUID2 are all excellent for distributed microservices because they require no coordination between nodes. UUID v7 and ULID add time-sorting for better database performance, while CUID2 provides anti-fingerprinting properties. Avoid Snowflake IDs in dynamic environments because they require worker-ID coordination.

Can I use different ID formats in different parts of my system?

Yes, and this is a common pattern. For example, you might use UUID v7 for database primary keys (time-sorted, standard format), Nano ID for user-facing short codes (compact, URL-safe), and Snowflake IDs for event streams (64-bit integer, high throughput). The key is to standardize within each bounded context to keep parsing and storage simple.

© 2024 Carova Labs. All rights reserved