Glossary · PHP & Backend

What is a UUID (universally unique identifier)?

Short answer

A UUID (universally unique identifier) is a 128-bit value used as an ID that is practically guaranteed to be unique without a central authority, written as 36 characters like 550e8400-e29b-41d4-a716-446655440000. Any system can generate one independently, which suits distributed systems, public URLs and idempotency keys. UUIDv7 adds a timestamp so IDs sort by creation time.

Versions you will meet

  • UUIDv4: random. Unique, but random values scatter inserts across a database index, which slows down large tables.
  • UUIDv7 (RFC 9562, 2024): starts with a millisecond timestamp, so new IDs sort in time order and index well. The best default for new database keys.
  • UUIDv5 / v3: derived from a name and namespace, so the same input always gives the same UUID.

UUIDs or auto-increment IDs?

  • Use UUIDs when IDs are created in many places (offline apps, several services), appear in public URLs (they don’t reveal how many records you have), or are needed before the database insert.
  • Auto-increment integers are smaller, faster and easier to read, and fine for internal tables.

Many teams keep an integer primary key internally and expose a UUID publicly.

In PHP

Laravel’s HasUuids and HasVersion7Uuids traits generate them for Eloquent models, and Symfony’s Uid component and ramsey/uuid cover the other versions. Store them in a native uuid column in PostgreSQL, or BINARY(16) in MySQL, rather than as text.

Published · Updated · By · All terms

Go deeper