DevelopmentIntermediate📖 12 min read📅 2026-02-01

Complete Guide to UUID Generation and Usage

Learn UUID version characteristics, appropriate use cases, and practical implementation methods

#UUID#unique identifier#database#API

Complete Guide to UUID Generation and Usage

UUID (Universally Unique Identifier) is a standard method for generating globally unique identifiers. UUIDs are used when you need duplicate-free IDs in databases, APIs, and distributed systems.

1. UUID Basic Concepts

A UUID is a 128-bit number, represented as a 36-character string in the format 550e8400-e29b-41d4-a716-446655440000.

UUID Characteristics:

  • Extremely low probability of duplication (practically guaranteed uniqueness)
  • Can be generated independently without central management
  • Safe to use in distributed systems

2. UUID Version Characteristics

Version 1 (Time-based)

Generated using timestamps and MAC address.

  • Pros: Guarantees chronological order
  • Cons: Privacy concerns due to MAC address inclusion

Version 4 (Random)

Generated using completely random values.

  • Pros: Unpredictable, privacy-safe
  • Cons: No chronological order
  • Most commonly used

Version 5 (Name-based)

Generated by SHA-1 hashing namespace and name.

  • Pros: Same input always produces same UUID
  • Use case: When deterministic IDs are needed

3. Practical Use Cases

Database Primary Keys

CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name VARCHAR(255),
  email VARCHAR(255)
);

API Resource Identifiers

// RESTful API endpoint
GET /api/users/550e8400-e29b-41d4-a716-446655440000

File Name Generation

const fileId = crypto.randomUUID();
const filename = `upload-${fileId}.jpg`;

이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

4. Implementation Methods and Best Practices

JavaScript/Node.js

// Browser/Node.js 18+
const uuid = crypto.randomUUID();

// Node.js (uuid package)
const { v4: uuidv4 } = require('uuid');
const uuid = uuidv4();

Python

import uuid

# Generate UUID v4
my_uuid = uuid.uuid4()
print(str(my_uuid))

Best Practices

  1. Choose appropriate version: Use v4 for most cases
  2. DB Indexing: Consider index optimization when using UUID as primary key
  3. Security: Be cautious of MAC address exposure with v1
  4. Performance: Check library benchmarks for bulk generation

Related Tool: Try generating various UUID versions right away with 🔑 UUID Generator!

Complete Guide to UUID Generation and Usage | DDTool