यह कैसे काम करता है
UUID version 4 is 122 random bits with six bits reserved to mark the version and variant, rendered as 32 hexadecimal digits in five hyphenated groups. Its appeal is that generation requires no coordination at all: two machines that have never met can each mint an identifier and the collision probability is negligible. The cost is that the values are uniformly random, so inserting them into a B-tree index scatters writes across the whole tree, and a bulk import of a million rows touches a million different pages. On a large table that is a measurable throughput problem.
UUID version 7 solves exactly that by placing a 48-bit millisecond timestamp in the most significant bits, followed by random data. Because the values increase with time, they append to the end of an index rather than scattering through it, keeping write performance close to that of a sequential integer while retaining enough randomness to be unguessable. The trade is that the timestamp is visible to anyone holding the identifier, which reveals when a record was created and roughly how many exist — sometimes useful, sometimes a leak.
ULID applies the same idea with a different encoding: 48 bits of millisecond timestamp followed by 80 bits of randomness, rendered in Crockford Base32, which is case-insensitive and omits the letters I, L, O and U to remove visual ambiguity. The result is 26 characters, lexicographically sortable, and safe in a URL or a filename without escaping. Nano ID takes the opposite approach: a compact alphabet of URL-safe characters, defaulting to 21 characters and about 126 bits of entropy, tuned for the shortest identifier that is still collision-safe.
MongoDB ObjectId is the odd one out but follows the same trend. It is 12 bytes: four bytes of seconds since the epoch, five bytes of random per-process value and a three-byte counter. It is sortable by creation time, shorter than a UUID and designed for a specific database's indexing behaviour. Passwords are generated from a configurable character set with the entropy stated in bits, which is the number that actually matters — length alone is a poor proxy, since a 16-character password drawn from a 26-letter alphabet carries far less entropy than an 11-character one drawn from the full 94 printable ASCII characters.
सामान्य उपयोग के मामले
- Generate primary keys for a new table where sortable, index-friendly identifiers matter.
- Create correlation IDs to trace a request across multiple services in a distributed system.
- Produce unique filenames or object storage keys without a central counter.
- Mint opaque session or invitation tokens that reveal nothing about the record behind them.
- Generate test fixtures that need realistic identifiers at scale.
- Create strong random passwords or API secrets with a known entropy figure.
अंतिम अद्यतन: 2026-10-14 — लेख का मुख्य भाग अंग्रेज़ी में दिखाया गया है; इंटरफ़ेस का अनुवाद हो चुका है।