What is a UUID and what is it used for?+
A UUID is a 128-bit identifier formatted as 8-4-4-4-12 hexadecimal characters. It's used as a unique key for database records, session tokens, and any place you need an ID that won't collide across systems.
Is UUID v4 truly unique?+
In practice, yes. UUID v4 uses 122 bits of randomness, giving 2^122 possible values. The probability of a collision is astronomically low - you'd need to generate billions of UUIDs per second for billions of years to expect one.
What is the difference between UUID v1 and v4?+
UUID v1 is based on the machine's MAC address and current timestamp, making it traceable. UUID v4 is entirely random and is the preferred choice for most applications.
Can I use the generated UUIDs as database primary keys?+
Yes. UUID v4 works well as a primary key in PostgreSQL (UUID type), MySQL (CHAR(36) or BINARY(16)), and MongoDB. Note that random UUIDs can cause index fragmentation in very large tables - consider UUIDv7 or ULID for sequential IDs.