CMD Guide
HomeSystem DesignScalable Systems (Advanced Topics)

What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose

UUID, ULID, KSUID, and Snowflake ID are all schemes for generating globally unique identifiers.

In brief, UUIDs are 128-bit random identifiers, ULIDs and KSUIDs are time-encoded identifiers (128-bit and 160-bit respectively) that sort in creation order, and Snowflake IDs are 64-bit numeric identifiers combining a timestamp, machine ID, and sequence counter.

Each format trades off size, readability, and ordering guarantees to suit different distributed-system needs.

What is a UUID?

A UUID (“Universally Unique Identifier”, also known as GUID) is a 128-bit value (typically shown as a 36-character hex string) designed to be globally unique.

There are several versions, but the common one (version 4) is purely random (with 122 random bits and a few fixed version bits).

Because of its randomness, a UUIDv4 requires no coordination or central service: you can generate them independently on any machine and collisions are exceedingly unlikely.

What is a ULID?

ULID stands for Universally Unique Lexicographically Sortable Identifier.

A ULID is a 128-bit ID (like a UUID) but structured as 48 bits of timestamp (milliseconds since Unix epoch) followed by 80 bits of randomness. It is typically encoded in a 26-character Base32 string (Crockford’s alphabet), e.g. 01ARZ3NDEKTSV4RRFFQ69G5FAV.

Differences Between UUID, ULID, KSUID, and Snowflake IDs
Differences Between UUID, ULID, KSUID, and Snowflake IDs

What is a KSUID?

KSUID stands for K-Sortable Unique Identifier. It is a 20-byte (160-bit) ID introduced by Segment.

A KSUID contains a 32-bit timestamp (seconds since a custom epoch in May 2014) followed by 128 bits of randomness.

The timestamp is big-endian so that the binary or text representation sorts by creation time. KSUIDs are encoded as 27-character Base62 strings (alphanumeric).

What is a Snowflake ID?

Snowflake IDs were created by Twitter (now X) for generating unique 64-bit integers across distributed systems.

A standard Snowflake ID has 64 bits (with 63 bits used for positive range):

Key Differences

When to choose which

Practical Scenarios

Compact comparison table

SchemeSizeSortable by timeCoordinationCollision resistanceBest for
UUIDv4128 bit / 36 charsNoNone122 random bitsUser IDs, API tokens, public URLs
ULID128 bit / 26 charsYes (ms)None80 random bitsEvent logs, ordered streams
KSUID160 bit / 27 charsYes (s)None128 random bitsHigh-scale event systems
Snowflake64 bit / 8 bytesYes (ms)Worker ID + clock syncTime/sequence uniquenessTwitter-style tweets, integer PKs

Index fragmentation: why random IDs hurt write-heavy tables

Inserting 1 million rows with UUIDv4 primary keys into a B-tree index forces random leaf-page writes. With ULIDs or Snowflakes, new keys append to the right side of the index, yielding mostly sequential I/O and higher cache locality.

Concrete example: a write-heavy table on a single NVMe SSD might sustain 50,000 inserts/sec with sequential integer keys but only 15,000–20,000 inserts/sec with random UUIDs due to page splits and buffer-pool churn.

Snowflake operational gotchas

Drill ladder

UUIDv7: the standard that narrows ULID's niche

The four formats above are the classic set, but there is now a fifth answer that a current interviewer expects you to know. UUIDv7, standardized in RFC 9562 (2024, which obsoleted RFC 4122), is a 128-bit UUID laid out as a 48-bit Unix-millisecond timestamp followed by version/variant bits and ~74 bits of randomness. In other words, it is essentially "ULID's idea, but as an official UUID." That combination is powerful: you get ULID's time-ordered index locality and drop-in compatibility with the native UUID column type that databases already optimize (Postgres, SQL Server, etc.), with no custom library on the storage side.

The practical consequence: for a brand-new system that wants sortable keys, UUIDv7 is now the strong default, and it shrinks the case for ULID (whose main advantage was being time-ordered where UUIDv4 was not). You would still reach past UUIDv7 for a smaller key — Snowflake's 8 bytes vs UUIDv7's 16 — when index size and integer-key ergonomics dominate. So the modern decision reads: UUIDv7 for a standard 128-bit time-ordered key with zero coordination; Snowflake when you need the compact 64-bit integer and can manage worker IDs.

The security trade-off: time-ordered IDs leak business volume

Sortability is not free. Any ID that embeds a timestamp or a monotonic counter — Snowflake, ULID, KSUID, UUIDv7, and especially a plain auto-increment integer — leaks information to anyone who can see it. Two consequences to state explicitly:

This is the one axis where UUIDv4's pure randomness is the feature, not a drawback: it exposes neither order nor time. The clean resolution in practice is to decouple the two concerns — use a time-ordered ID (UUIDv7/Snowflake) as the internal primary key for index locality, and expose an opaque, random public identifier (UUIDv4, or a hashid/random token) in URLs and APIs. Never let the index-performance choice dictate what you leak to the outside world.

🤖 Don't fully get this? Learn it with Claude

Stuck on What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose** (System Design) and want to truly understand it. Explain What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes