Most developers use UUIDs without thinking about why. They generate one, stick it in a database column, and move on. But UUIDs solve specific problems that other ID formats cannot. Knowing which problem you are solving helps you pick the right version and avoid the wrong tradeoffs.
Here are the use cases where UUIDs are not just acceptable — they are the right tool.
UUID for Distributed Systems
This is the original problem UUIDs were designed to solve. In a distributed system, multiple nodes generate IDs concurrently. You cannot coordinate with a central counter without creating a bottleneck.
UUIDs let every node generate IDs independently. Two nodes producing f47ac10b-58cc-4372-a567-0e02b2c3d479 and 7c9e6f3a-2b1d-4e8c-a5f6-1d2e3f4a5b6c at the same time will not collide. No coordination needed. No central authority.
Real example: a multi-region deployment with write nodes in US-East, EU-West, and AP-Southeast. Each node generates UUIDs for new orders. The orders replicate to a central database. No collisions, no ID conflicts, no renumbering.
For this use case, v4 is the standard choice. If you need chronological ordering across nodes, v1 works but leaks the MAC address — use it only inside a trusted network. See our UUID v1 vs v4 vs v5 guide for the version tradeoffs.
UUID for Game Development
Games generate a lot of unique entities: players, items, matches, sessions, quests. In a multiplayer game with a central server, the server can assign integer IDs. In a peer-to-peer or offline-first game, clients generate entities locally and sync later.
UUIDs let a client create an item offline — say, a sword with ID 3a2b1c8e-4d6a-7f5b-9e8c-1d2e3f4a5b6c — and sync it to the server without collision. The server has never seen this ID before, but it does not need to. The UUID is globally unique by construction.
Real example: a mobile RPG where players collect items offline. Each item gets a UUID when picked up. When the player reconnects, the client syncs all new items. The server accepts them without checking for ID conflicts because UUIDs do not conflict.
UUID for API Keys
API keys need to be unguessable, unique, and easy to generate at scale. UUID v4 is 122 bits of randomness. That is more than enough for an API key — guessing a specific v4 UUID by brute force is computationally infeasible.
python import uuid api_key = uuid.uuid4() # f47ac10b-58cc-4372-a567-0e02b2c3d479
A bare UUID is a decent API key, but most systems add a prefix for readability and routing: nc_live_f47ac10b-58cc-4372-a567-0e02b2c3d479. The prefix does not add entropy. It adds operational clarity — you can tell a live key from a test key at a glance.
For API keys, always use v4. Never v1 (leaks MAC address), never v5 (deterministic, guessable if the namespace and name are known). See our UUID generator to generate v4 UUIDs for this purpose.
UUID for Session Tokens
Session tokens identify a user session. They need to be unguessable (so an attacker cannot hijack a session by guessing the token) and unique (so two sessions do not collide).
UUID v4 satisfies both. 122 bits of randomness means the probability of guessing a specific session token is 1 in 2^122. That is secure.
However, a bare UUID is not a complete session solution. You also need: - An expiration time - A binding to the user ID - A revocation mechanism - Secure transmission (HTTPS)
The UUID is the token identifier. The rest is session management. Do not use a UUID as the only authentication factor — use it as the session handle that your server maps to an authenticated user.
UUID for File Deduplication
If two users upload the same file, you do not want to store it twice. Hash the file content (SHA-256) and use the hash as the storage key. But if you also want a stable identifier that does not depend on file content — for example, to track the file across content changes — use a UUID.
Real example: a document management system assigns each uploaded document a UUID on first upload. If the document is revised, the UUID stays the same and a new version number is appended. The UUID is the document identity. The version number tracks revisions.
UUID for Event Sourcing and CQRS
Event sourcing stores every state change as an immutable event. Each event needs a unique ID. UUIDs are the standard choice because: - Events are generated concurrently across services - Events must be unique forever (for replay and audit) - Events may be generated before the event store is available (offline, buffering)
javascript const event = { id: crypto.randomUUID(), type: 'OrderPlaced', aggregateId: '7c9e6f3a-2b1d-4e8c-a5f6-1d2e3f4a5b6c', timestamp: Date.now(), payload: { items: [...] } };
## UUID for Tracking and Analytics
Click tracking, page view tracking, and conversion tracking need unique IDs for each event. UUIDs let the client generate the ID before sending the event, which means: - No round-trip to get an ID - Deduplication on the server (same UUID = same event, not a duplicate) - Offline tracking that syncs later
When NOT to Use UUIDs
- **Internal counters.** If you just need a sequence number, use an integer. - **Short public IDs.** Use NanoID or a short URL code. See UUID vs NanoID vs ULID. - **Human-readable IDs.** Use slugs (my-blog-post) not UUIDs. - **When sortability matters more than uniqueness.** Use ULID or a timestamp-based ID.
For generating UUIDs for any of these use cases, use our UUID generator. For the collision math behind why UUIDs are safe, read can two UUIDs ever be the same.