About UUIDs
A UUID (Universally Unique Identifier) is a 128-bit identifier used to uniquely identify information in computer systems. UUIDs are standardized by RFC 4122 and are designed to be unique across time and space without requiring a central registration authority.
UUID Versions
- UUID v4 (Random): Generated using random or pseudo-random numbers. This is the most common type used in applications.
- UUID v1 (Time-based): Generated based on the current timestamp and MAC address.
- UUID v3 & v5 (Name-based): Generated using a namespace and a name, using MD5 (v3) or SHA-1 (v5) hashing.
Common Use Cases
- Database Primary Keys: Use UUIDs as primary keys to avoid collisions across distributed systems
- Session IDs: Generate unique session identifiers for web applications
- API Tokens: Create unique API keys and authentication tokens
- File Names: Generate unique file names to prevent overwrites
- Distributed Systems: Create unique identifiers without central coordination
Best Practices
- Use UUID v4 for most applications as it provides good randomness
- Store UUIDs as binary (16 bytes) in databases for better performance
- Consider using UUIDs when building distributed or microservices architectures
- Be aware that UUIDs are longer than sequential IDs and may impact URL readability