What is UUID
Learn about Universally Unique Identifiers, their structure, versions, and use cases in software development.
1. What is UUID
UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify information in computer systems. UUIDs are designed to be unique across space and time without requiring a central coordinating authority. A UUID is typically represented as a string of 32 hexadecimal digits, displayed in five groups separated by hyphens in the form 8-4-4-4-12 characters. There are several versions of UUID, each generated using a different method: Version 1 uses timestamp and MAC address, Version 4 uses random or pseudo-random numbers, Versions 3 and 5 use hash-based name-based generation. The probability of generating a duplicate UUID is extremely low, making them suitable for distributed systems.
2. Why It Matters
UUIDs are fundamental for generating unique identifiers in distributed systems, databases, and APIs. Unlike auto-increment integers, UUIDs do not reveal information about data volume or ordering, which can be a security benefit. They allow identifiers to be generated independently by different systems without coordination, which is essential for microservices and distributed architectures. Understanding UUID versions helps choose the right one for specific use cases.
3. Example
Format: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
Example: 550e8400-e29b-41d4-a716-446655440000
M = Version (4 = random)
N = Variant (10xx = RFC 4122)A UUID has 128 bits, represented as 32 hex characters in 5 groups. The M nibble indicates the version, and the N nibble indicates the variant.
4. Common Mistakes
1. Using wrong UUID version
Choose the right version for your use case. Use v4 for random IDs, v1/v5 if you need deterministic IDs.
2. Storing as strings inefficiently
UUIDs stored as strings take 36 bytes. Consider storing as binary (16 bytes) for better performance.
3. Assuming sequential ordering
Most UUID versions are not sequential. Do not rely on UUID ordering for sorting.
4. Using UUIDs for everything
UUIDs have overhead. For small, internal systems, auto-increment IDs may be more efficient.
5. Related Tools
FAQ
Try Our Free Developer Tools
Put your knowledge into practice with our free online developer tools. All tools work directly in your browser with no installation required.