Pros
Collision Resistance
The odds of two codes ever colliding, having the same value, are vanishingly small.
A discussion on the chances of collision is here.
The algorithm, codeGenerator.js, can be viewed
here on github.
Identification of the Point of Origin
Unique error codes help developers quickly locate a specific issue which occurred in
the codebase. When the codebase is modified or reorganized, the unique error error code
can potentially still communicate the same issue, even if multiple releases exist in
the field.
Cryptographic Quality Randomness
It uses the platform's CSPRNG, so the output is unpredictable and well-distributed, which
is much better than Math.random() based approaches.
Compact Representation
A raw UUID is 36 characters (with hyphens) or 32 hex digits. Converting the 128-bit value
to base62 yields roughly 22 characters, which is meaningfully shorter while remaining
URL-safe and human-typeable.
No Special Characters
Base62 (0–9, a–z, A–Z) is URL-safe, filename-safe, and readable in logs, emails, and
support tickets without escaping or encoding.
Stateless Generation
No database sequence and no coordination between servers is required. Any instance can
generate a code independently, which scales well.
Universally Available
crypto.randomUUID() is available natively in Node.js 14.17+, all modern browsers, and
Deno. No dependencies are needed.
Cons
Not Truly 22 Characters
Due to how BigInt conversion works with the full 128-bit UUID
value, you'll get a variable-length string which is up to ~22 chars.
Loses UUID Structure
A raw UUID v4 has a well-known format that tools, databases, and libraries understand
natively. Once converted to base62, you lose that interoperability.
Case Sensitve
Base62 includes both upper and lowercase letters, so ABC123 ≠ abc123.
This can cause user reporting errors in phone support contexts.
No Intrinsic Meaning.
The unique error code carries zero metadata. It has no timestamp, no service
identifier, no severity. Systems like Sentry embed structured info in error IDs.
If you ever want to decode "when did this happen" or "which service threw this,"
a pure random code won't help.
Overkill for Many Error Reporting Volumes
If your application generates thousands, not billions, of errors, even a simple
nanoid or sequential ID would have negligible collision risk. The full UUID to
base62 pipeline is robust but adds complexity that may exceed what the problem
actually demands.