DEV Community

Cover image for Which UUID version?
aakhtar3
aakhtar3

Posted on

4

Which UUID version?

Which UUID version?

Universally Unique IDentifiers versions are defined by the RFC4122.

They are 5 different versions that have different implementations to generate Unique Identifiers.

v1 Time

Uses the CPU clock cycle to calculate a unique ID

v2 MAC

Uses the CPU clock cycle and MAC address to generate a unique ID.

v3 MD5

Uses a namespace value to salt the MD5 Hash (128 bits).

v4 Random

Uses Pseudo-random numbers to generate a unique ID.

v5 SHA-1

Uses a namespace value to salt the SHA-1 Hash (160 bits).

API

Generally, a UUID library will expose all 5 versions and a few helper functions.

  • Version: Provides UUID RFC version
  • Parse: Convert UUID string to array of bytes
  • Stringify: Convert array of bytes to UUID string
  • Validate: Check if UUID is valid
  • Nil: All bits are set to 0
    • 00000000-0000-0000-0000-000000000000

Ranking

Uniqueness

v1 ๐Ÿ‘Š v2 ๐Ÿ‘Š v4

v4 Random

v1 and v2 are similar, but the cpu cycle is predictable.

Hashing

v3 ๐Ÿ‘Š v5

v5 SHA-1

v5 SHA-1 has a stronger encryption than v3 MD5.

Protected

v2 ๐Ÿ‘Š v1 ๐Ÿ‘Š v4 ๐Ÿ‘Š v3 ๐Ÿ‘Š v5

v5 SHA-1

v1 and v2 are similar, but the MAC address can make your system less secure.

Overall

v1 ๐Ÿ‘Š v2 ๐Ÿ‘Š v3 ๐Ÿ‘Š v5 ๐Ÿ‘Š v4

v4 Random

v4 is generally the best option in most use cases.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

๐Ÿ‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Communityโ€”every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple โ€œthank youโ€ goes a long wayโ€”express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay