Why UUIDs matter in modern backends
Universally unique identifiers let independent services mint IDs without a central allocator. That makes UUIDs ideal for microservices, offline-first clients, and event logs.
UUID v4 vs UUID v7
UUID v4 is random. It is simple and widely supported, but random insertion order can fragment B-tree indexes in PostgreSQL or MySQL.
UUID v7 embeds a timestamp in the high bits. New rows cluster more naturally in time-ordered indexes while staying globally unique.
Database indexing tips
- Prefer UUID v7 for primary keys on high-write tables.
- Store UUIDs as native UUID/binary types, not varchar, when your database supports it.
- Avoid converting UUIDs to strings in hot query paths.
- If you must sort by creation time, v7 gives you that for free.
When not to use UUIDs
Sequential integers are still fine for internal-only tables with a single writer. UUIDs shine when multiple writers or public IDs are involved.
Try the free UUID Generator on Zovaty Tools to generate v4 and v7 identifiers locally in your browser.