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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay