What is a UUID?
A UUID is a universally unique identifier used to label records, resources and events. Version 4 UUIDs are generated from random data and are common in distributed systems.
Why Developers Use UUIDs
- Create public identifiers that are hard to guess
- Generate IDs across multiple services
- Avoid coordination between distributed systems
- Create reliable test data
- Identify API resources consistently
UUIDs vs Auto-Increment IDs
Auto-increment IDs are simple and efficient, but they reveal sequence information. UUIDs are larger, but they are useful when IDs are generated outside a single database or exposed publicly.
Best Practices
Use UUIDs when distributed generation, public resource IDs or hard-to-guess identifiers are useful. For high-volume database tables, review indexing strategy because UUIDs are larger than integer IDs.