Backendbeginner

UUID

A universally unique identifier — a long random string used as a unique ID for database rows instead of simple numbers.

Detailed Explanation

A UUID (Universally Unique Identifier) is a 128-bit identifier that looks like this: 550e8400-e29b-41d4-a716-446655440000. It's used as the primary key for rows in a database table.

Why UUIDs Instead of Numbers?

You might wonder why not just use 1, 2, 3 as IDs. UUIDs solve several problems:

  • No collisions — Two different systems can generate UUIDs independently and they'll never clash
  • Security — You can't guess someone else's ID (with numbers, if your ID is 5, you know ID 4 and 6 exist)
  • Distributed systems — Multiple servers can create records simultaneously without coordinating

UUIDs in Supabase

Supabase uses UUIDs everywhere. When you create a table, the id column is typically a UUID that auto-generates using gen_random_uuid(). The auth.users table also uses UUIDs, so when you create a foreign key like user_id, it references a UUID.

In Practice

You rarely type UUIDs yourself. The database generates them automatically. You just reference them in queries and foreign keys:

CREATE TABLE notifications (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
  user_id UUID REFERENCES auth.users(id)
);

UUIDs are standard across SQL databases and are the default ID type in modern web development.

Ready to Build Something Real?

We give you the skills to build, deploy, and own a full product. Professional stack, AI co-pilot, no coding background required.