What a UUID is and when to use one
A UUID (Universally Unique Identifier), also called a GUID, is a 128-bit value written as 32 hexadecimal digits in five hyphen-separated groups, like 550e8400-e29b-41d4-a716-446655440000. Its purpose is to let separate systems generate identifiers that will not clash, without any central authority handing out numbers. That makes UUIDs ideal for distributed systems, databases and APIs where many machines create records independently.
Why collisions effectively never happen. The most common type, version 4, is almost entirely random, drawing from so vast a space (over 10^36 possibilities) that the odds of two randomly generated UUIDs matching are negligible even across billions of them. That is the whole point: you can generate one anywhere, any time, and trust it is unique without checking.
When to reach for one. Use a UUID as a primary key when records are created across multiple servers or offline clients, or when you do not want sequential IDs exposing how many records exist or letting people guess the next one. The trade-off is that they are longer and less human-friendly than a simple counter, so for a small single-database app an auto-incrementing ID is often simpler.