Universally unique identifier

Photo by Nick Fewings on Unsplash

Also known as uuid.

A concept that has increased his presence in my everyday work.

An uuid is a 128-bit number that is most often know to our eyes as a string that looks like this:


For me, this strings replaced the classic incremental id used for identify rows / documents in a database table / collection.

At that time, my naive programmer’s mind was telling me that this strings are random and unique regardless of how many I generate, as long as I don’t need more that the total possible combinations.

And there are a lot of them.

But, deep inside my simple yet chaotic mind, a question has been born:

How is this generator thing keep track of the already generated numbers? What is this sorcery all about?

It turns out that there are some trade-offs made here.

There are multiple versions, with slightly different concepts that solve different problems.

For example, Version 1 uses a MAC address and the date-time at the cost of randomness in order to ensure the uniqueness of the uuid’s. That makes it easily guessable and not suited for certain scenarios.

On the other hand, Version 4 (the one that I used for rows / documents ids) is all randomly generated, which comes with a very small probability of collision.

Yep, there is a chance that I will mess up some data, a small one tho.

If you are unsure of what version you’re using, there is a character in the string representation that is reserved for that. e.g. Version 4 looks like this:


Here is more information about other versions and this topic.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑