Examples
UUID v4: 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d (completely random)UUID v7: 018e8c4e-1a2b-7c3d-8e4f-9a0b1c2d3e4f (timestamp-sortable)Postgres: CREATE TABLE users (id UUID PRIMARY KEY DEFAULT gen_random_uuid());
FAQ
Can UUIDs collide?
Theoretically yes, but with astronomically low probability. In UUID v4 you would need to generate 2.71 × 10^18 UUIDs to have a 50% chance of collision. In practice it's impossible.
Are UUIDs slower than integers in databases?
UUID v4 yes, due to index fragmentation. UUID v7 solves this by being sortable, achieving similar performance to BIGSERIAL in Postgres with the advantages of distributed generation.
Can I use UUIDs as authentication tokens?
Technically yes, but not recommended. For session tokens or API keys use specific generators with more entropy (256+ bits) and consider adding a prefix to identify token type.