A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify objects in computer systems. The standard format is 8-4-4-4-12 hexadecimal digits separated by hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
What makes UUID v4 special? โผ
UUID v4 is randomly generated using cryptographically secure random numbers. The probability of collision is astronomically small โ you'd need to generate 1 billion UUIDs per second for about 85 years before expecting a collision. This makes them safe to use as database primary keys.
When should I use UUIDs? โผ
Use UUIDs when: (1) you need globally unique IDs across multiple systems, (2) you don't want to expose sequential IDs, (3) generating IDs on the client side before database insertion, (4) in distributed systems where multiple nodes create records independently.