Everything you need to use UUIDs correctly in a real project: how to store them efficiently, what they do and do not protect, and how to generate them across languages and frameworks.
What these guides cover
UUID generation is a single function call in most languages. The harder questions are about what happens next: which column type to use, why your database index slows down after a million rows, what a UUID in a URL actually leaks, and when to reach for v7 instead of v4. These guides answer those questions with concrete recommendations rather than general overviews.
Choosing the right UUID version
The practical choice for new projects in 2026 is between v4 and v7. UUID v4 is 122 bits of cryptographic randomness — unpredictable, no timestamp, nothing derivable about when or where it was created. UUID v7 embeds a 48-bit Unix millisecond timestamp in its leading bits, making it time-sortable and index-friendly. The UUID Versions guide covers all eight versions defined by RFC 9562, including which are deprecated (v1, v2, v6) and when name-based v5 is the right choice.
UUIDs and database performance
Random UUID v4 primary keys cause B-tree page splits on every insert because each new value lands at a random position in the index. At scale — hundreds of thousands of rows — this fragments the index, increases cache misses, and measurably slows both writes and range reads. UUID v7 eliminates this problem: its timestamp prefix means consecutive inserts cluster near the end of the index, producing behaviour close to an auto-increment integer. The UUID in Databases guide covers storage types, index behaviour, and migration paths for PostgreSQL, MySQL, SQLite, SQL Server, and MongoDB.
Security and what UUIDs are not
A UUID is an identifier, not a secret. Even UUID v4, with its 122 bits of randomness, should not be used as a session token or capability grant on its own — UUIDs appear in URLs, server logs, referrer headers, and anywhere HTTP traffic is recorded. The UUID Security guide explains what v4 actually guarantees, what v7 leaks (creation timestamp to the millisecond), and what to use instead when you genuinely need a secret.
Language guides
Each language guide shows the idiomatic way to generate, parse, and store UUIDs — covering the standard library where it exists and the canonical third-party package where it does not. All guides include v7 examples, database storage patterns, and framework-specific integration (ORMs, web frameworks, type systems).
- JavaScript / Node.js —
crypto.randomUUID(), theuuidnpm package, React, Vue, Prisma, Drizzle - Python — built-in
uuidmodule, v7 in Python 3.13+, Django, SQLAlchemy, Pydantic, FastAPI - Go —
google/uuid, pgx, database/sql, GORM, structured logging
All guides
All eight RFC 9562 versions explained — what each one does, which are deprecated, and how to choose between v4 and v7 for new work.
Databases UUID in DatabasesStorage types, B-tree index behaviour, PostgreSQL and MySQL setup, and how to migrate an existing table from v4 to v7.
Security UUID SecurityWhat the randomness in v4 actually guarantees, what v7 leaks, and when to use a real secret instead of a UUID.
Fundamentals UUID vs GUIDGUID is Microsoft's name for the same 128-bit standard. How the terms differ, SQL Server's byte-order caveat, and .NET's Guid type.
Comparison UUID vs ULIDBoth are 128-bit time-sortable identifiers. How encoding, monotonicity, and database support differ, and when to choose each.
JavaScript UUID in JavaScriptcrypto.randomUUID(), the uuid npm package, React and Vue patterns, Prisma, Drizzle, and a TypeScript branded-type recipe.
Python UUID in PythonThe built-in uuid module, v7 in Python 3.13+, the uuid6 backport, and patterns for Django, SQLAlchemy, Pydantic and FastAPI.
Go UUID in Gogoogle/uuid for v4 and v7, parsing and validation, pgx and database/sql integration, GORM hooks, and typed UUID patterns.
Frequently asked questions
Should I use v4 or v7?
Use v7 for database primary keys (time-sortable, index-friendly) and v4 for anything where creation order could leak information, like tokens or share links.
Where can I learn more about UUID best practices?
The Guides section covers UUID versions, databases, security, JavaScript, Python, Go, UUID vs GUID, and UUID vs ULID — each with concrete recommendations for real projects.