What is uuid in database

Last updated: April 1, 2026

Quick Answer: UUID (Universally Unique Identifier) is a 128-bit value used in databases to uniquely identify records across systems without requiring central coordination. UUIDs are standardized globally and ensure uniqueness even when data is generated independently on different servers or merged from multiple sources.

Key Facts

What is a UUID?

A UUID (Universally Unique Identifier), also known as GUID (Globally Unique Identifier), is a standardized 128-bit value designed to be unique across all space and time. Unlike sequential auto-incrementing identifiers that depend on a central database, UUIDs can be generated independently by any system while maintaining guaranteed uniqueness.

UUID Structure and Format

A UUID is represented as 32 hexadecimal digits grouped in five sections: 8-4-4-4-12 format. For example: 550e8400-e29b-41d4-a716-446655440000. This standardized format is defined by RFC 4122 and ensures compatibility across different database systems and programming languages. The total length is 36 characters including hyphens, or 32 characters without them.

UUID Versions

The UUID standard defines several versions, each generating identifiers differently. UUID v1 combines timestamp and hardware MAC address, making it sequential and suitable for auditing. UUID v4 uses random generation and is most common in modern applications for its simplicity and security. UUID v5 generates identifiers from a namespace and name using SHA-1 hashing, useful when deterministic unique IDs are needed from specific data.

Database Integration

Most modern databases support UUID natively. PostgreSQL uses the uuid data type with the uuid-ossp extension. MySQL supports UUID through the UUID() function. MongoDB uses ObjectId by default but supports UUID. Each database provides functions to generate and store UUIDs efficiently, though storage overhead is greater than sequential integer identifiers.

Advantages and Trade-offs

UUIDs eliminate the need for central ID coordination in distributed systems, making them ideal for microservices and multi-database architectures. They prevent ID collisions when merging data from independent sources. However, UUIDs consume more storage space, create larger indexes, and are non-sequential, which can reduce database performance compared to incremental integers in some scenarios.

Related Questions

What is the difference between UUID and GUID?

UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier) are essentially the same thing. GUID is Microsoft's term, while UUID is the standardized name defined by RFC 4122 used across other platforms.

Can two UUIDs ever be the same?

The probability of UUID collision is astronomically low. UUID v4 uses random generation with enough entropy that collisions are theoretically possible but practically negligible for any real-world application.

When should I use UUID instead of auto-increment IDs?

Use UUIDs for distributed systems, mobile apps with offline data, multi-database systems, or privacy-focused applications. Use auto-increment for single-server applications where sequential IDs are preferred.

Sources

  1. Wikipedia - Universally Unique Identifier CC-BY-SA-4.0
  2. RFC 4122 - A Universally Unique Identifier IETF Trust