Devkitrdevkitr
Generators

UUID Guide — Versions, Formats & When to Use Them

2025-12-288 min read

UUIDs (Universally Unique Identifiers) are 128-bit identifiers used to uniquely identify resources across distributed systems without a central authority. They are fundamental in databases, APIs, and microservices.


UUID Format


A UUID consists of 32 hexadecimal characters displayed in 5 groups separated by hyphens:


550e8400-e29b-41d4-a716-446655440000


Format: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx


Where M indicates the version and N indicates the variant.


UUID Versions


UUID v1 — Time-based

Generated from the current timestamp and the machine's MAC address. Guarantees uniqueness but reveals the creation time and hardware identity.


  • Pros: Naturally sortable by time, guaranteed unique
  • Cons: Exposes MAC address (privacy concern), not random

  • UUID v4 — Random

    Generated from random or pseudo-random numbers. The most commonly used version in web development.


  • Pros: Completely random, no information leakage, easy to generate
  • Cons: Not sortable, theoretically possible (but astronomically unlikely) collisions

  • UUID v7 — Time-ordered Random (Newest)

    Combines a Unix timestamp prefix with random data. Provides the benefits of both v1 and v4 — sortable AND random.


  • Pros: Time-sortable, good database index performance, random suffix prevents prediction
  • Cons: Newer standard, not yet universally supported

  • UUID vs Auto-Increment IDs


    When to Use UUIDs

  • Distributed systems with multiple databases
  • Merging data from different sources
  • Client-side ID generation (before sending to server)
  • When IDs shouldn't be guessable (security)
  • Microservices architectures

  • When to Use Auto-Increment

  • Single database applications
  • When sequential ordering matters
  • When storage size matters (4 bytes vs 16 bytes)
  • Simple CRUD applications

  • Collision Probability


    For UUID v4, the probability of generating a duplicate is astronomically low. You'd need to generate about 2.71 quintillion UUIDs to have a 50% chance of a single collision. In practical terms, you could generate 1 billion UUIDs per second for 85 years before worrying.


    Database Considerations


  • UUIDs as primary keys can cause index fragmentation with B-tree indexes
  • UUID v7 solves this by being time-sortable (sequential insert pattern)
  • Consider using BINARY(16) instead of CHAR(36) for storage efficiency in MySQL
  • PostgreSQL has a native uuid type that stores efficiently

  • Generate UUIDs instantly with our UUID Generator.


    Related Articles

    Back to Blog