What Is a UUID and When to Use One

What Is a UUID and When to Use One

A UUID (Universally Unique Identifier), also called a GUID, is a 128-bit value that looks like f47ac10b-58cc-4372-a567-0e02b2c3d479. The point is that you can generate one anywhere, anytime, and be confident it will never collide with another. Here is when that is useful.

Why not just use 1, 2, 3?

Sequential numbers need a central authority (usually a database) to hand them out in order. UUIDs do not. That matters when:

  • You generate IDs on the client or across multiple servers before anything reaches the database.
  • You merge data from different systems and need to avoid clashes.
  • You do not want IDs to reveal how many records exist or to be guessable.

v4 is the one you usually want

UUID version 4 is random. It is the common default because it needs no coordination and no input, just randomness. Other versions exist (v1 is time-based, v7 is time-ordered and newer), but v4 covers most needs.

Generate one in your browser

  1. Open the UUID Generator.
  2. Generate one or many at once using your browser’s secure random source.
  3. Copy them.

Nothing is sent to a server.

A note on databases

UUIDs are great for uniqueness but are larger than integers and random v4 values can fragment database indexes. If you store huge volumes and care about index performance, look at time-ordered UUIDs (v7) or keep a separate integer primary key. For most apps, v4 is perfectly fine.

When you need a unique ID without asking a database first, generate a v4 UUID and move on.

← All posts