Generate UUIDs in application code, in the database, or from a command line—the right place depends on who owns the write and where the value is needed. Separately, choose the UUID version: v4 is random, v7 is time-ordered, and v3/v5 reproduce an identifier from a namespace and name. A UUID is a 128-bit value; the version determines how its bits are formed and what information they convey.
Choose where the UUID should be generated
Generation location and UUID version are separate decisions. An application can generate a v4 or v7 UUID before saving a record; a database can generate one as part of a write; a command-line tool can supply a value for a one-off task or script. Choose the location that fits ownership of the data, then select a version for its required semantics.
As an Amazon Associate I earn from qualifying purchases.
1. Generate it in application code
Use the UUID module or a maintained library for the language and runtime deployed by your application. Python’s uuid module documents uuid4 for random UUIDs and uuid3/uuid5 for deterministic namespace-and-name UUIDs. The uuidjs library documents JavaScript support for versions including v4, v5, and v7, and says its random generation uses the modern crypto API.
This approach is useful when the application owns record creation or needs the identifier before it contacts the database. Verify that the specific runtime and library release in use supports the version and API you plan to call. In particular, uuidjs says uuid@12 no longer supports CommonJS, so projects using that module format should check compatibility with their installed release.
#1 Best Overall
2. Let the database generate it
Database-side generation suits tables whose writes are owned by the database or where a column default should create the identifier. PostgreSQL 18 documents gen_random_uuid() and uuidv4() for random v4 UUIDs, plus uuidv7() for time-ordered UUIDs. Its UUID functions documentation covers generation, while the UUID type documentation explains its native UUID type, which accepts UUIDs regardless of origin or version.
Check the version actually deployed before using a generator: older PostgreSQL documentation describes only the v4 generator. Database support is not a guarantee that another database engine or an older release provides the same function names.
3. Generate one from Python’s command line
For a one-off value or a simple shell script, Python documents python -m uuid; without options, it generates a v4 UUID. The Python 3.13.6 documentation lists -u to choose a generation function and includes uuid1, uuid3, uuid4, and uuid5. The CLI was added in Python 3.12. Consult the Python uuid documentation for invocation details and the options available in the Python version installed on the machine.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 114. Use a library CLI in a JavaScript workflow
The uuidjs project documents a uuid command-line utility that defaults to v4 and offers other documented versions, including v7. It can be convenient when a development or scripting workflow already uses that library. Check the installed release’s CLI options and module-format compatibility rather than assuming every release behaves identically; the project notes that uuid@12 no longer supports CommonJS.
Rank #3
How do UUID versions differ?
The UUID format has 128 bits, or 16 octets. Versions assign different meanings and generation rules to those bits, so UUIDs should not be treated as interchangeable in every use case.
| Version | How it is generated | Best fit and trade-off |
|---|---|---|
| UUIDv4 | Random or pseudorandom data with the required version and variant bits. | Use when a random identifier is wanted and ordering by creation time is not a requirement. The UUID format does not encode a generation timestamp. |
| UUIDv7 | Includes a Unix-epoch timestamp in milliseconds in the most significant 48 bits, with randomness or optional monotonicity fields in the remaining bits. | Useful when broad time-based sorting is desirable. The timestamp makes approximate creation time discernible; timestamp-based sorting does not guarantee strict global ordering. |
| UUIDv3 and UUIDv5 | Deterministically derived from a namespace identifier and a name; Python documents MD5 for v3 and SHA-1 for v5. | Use when the same canonical namespace/name input must produce the same UUID. Standardize input normalization. The uuidjs project prefers v5 over v3 when backward compatibility is not a concern. |
| UUIDv1 and UUIDv6 | Legacy time-based versions with distinct version-specific behavior. | Do not assume their privacy or ordering properties match v4 or v7. Python describes v1 as based on host ID, sequence number, and current time. |
RFC 9562, the IETF UUID specification, states: “Implementations SHOULD utilize UUIDv7 instead of UUIDv1 and UUIDv6 if possible.” “SHOULD” is the standard’s normative guidance, not a performance benchmark.
Rank #4
- Used Book in Good Condition
What to check before adopting a workflow
- Generation ownership: Decide whether the application, database, or a developer shell is responsible for creating the identifier, and ensure other components can use it at the right time.
- Version support: Confirm the API exists in the exact language runtime, package release, and database version deployed. Do not infer support from another version’s documentation.
- Time disclosure: Choose v7 with the understanding that it exposes approximate creation time. Use v4 if that timestamp information is not wanted and random identifiers meet the need.
- Deterministic input: For v3/v5, agree on the namespace and canonical form of the name. Differences in normalization mean different inputs and can produce different UUIDs.
- Storage and transport: Agree on a canonical string form and byte order at system boundaries. Where feasible, native or binary storage uses less space than text; RFC 9562 advises binary storage where feasible, but that is standards guidance rather than a measured result for every database.
The choice is therefore not simply “which UUID generator is fastest.” The cited sources establish no cross-method performance comparison or adoption statistic. Choose based on version semantics, deployment support, data flow, and storage needs rather than an assumed speed advantage.
Recommended Free Tools
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




