What is a UUID?

What is a UUID?

Understanding UUIDs: Universally Unique Identifiers Explained

Introduction

Universally Unique Identifiers (UUIDs) play a crucial role in various computer systems and applications, providing a means to generate unique identifiers with an extremely low probability of collisions. In this article, we'll explore more about UUIDs.

What is a UUID?

A Universally Unique Identifier (UUID) is a 128-bit identifier designed to be globally unique across space and time. To ensure uniqueness, the UUID combines a number of components.

Which includes, timestamp, randomly generated component, and a reference to the host's network address. The timestamp is unique for every UUID created from a specific host, and the network address uniquely identifies a machine, thus those two factors should be enough to guarantee uniqueness.

UUID Structure

UUIDs are usually represented as a string of 32 hexadecimal characters, grouped as five sections. The common format is "8-4-4-4-12," where each segment represents the number of bits dedicated to a specific component. The structure may include a timestamp, clock sequence, and node identifier.

Below image shows the breakdown of a UUID for Version 1 and 2 :

Image source: https://www.mparticle.com/blog/what-is-a-uuid/

Read this if you want to understand more about UUIDs, else ignore its not something u must know for sure:

Binary Representation and 128 Bits:

  • At its core, a UUID is a 128-bit value, meaning it consists of 128 binary digits (0s and 1s)

  • So, each hexadecimal digit represents 4 bits. That's why, a UUID is often presented as a string of 32 hexadecimal characters

  • If we do the math, we get 32 characters × 4  bits/character=128 bits or 32 characters × 4 bits/character=128 bits

  • For example, consider the UUID: 550e8400-e29b-41d4-a716-446655440000. When converted to binary, it consists of 128 bits

Hexadecimal Representation and 32 Characters:

  • UUIDs are commonly represented as strings of 32 hexadecimal characters (0-9 and a-f)

  • Each pair of hexadecimal characters equals to 8 bits (4 bits per character × 2 characters). As there are 16 possible values for each character (0-9 and a-f), each pair represents 2^8 = 256 possible combinations

  • If we do the math, we get 32 characters => 16 pairs × 8 bits/pair = 128 bits

  • For example, in the UUID 550e8400-e29b-41d4-a716-446655440000, each pair of characters represents 8 bits in hexadecimal form

UUID Versions

There are several UUID versions, each with its own method of generation. The most commonly used one is UUID v4, which relies on random or pseudo-random numbers for uniqueness. Other versions may incorporate timestamps, MAC addresses, or names.

Use Cases of UUIDs

We have highlighted, common use cases for UUIDs, there are a lot more than the below mentioned, do explore then if you want to.

  1. Database Primary Keys: UUIDs are widely used as primary keys in databases, ensuring each record has a globally unique identifier without requiring centralized coordination

  2. Distributed Systems: In distributed systems, where data is spread across multiple nodes or servers, UUIDs help generate unique identifiers without the need for a central authority

  3. Web Development: UUIDs find applications in web development for creating unique identifiers for elements on a page or tracking user sessions

  4. Security: UUIDs are employed in security-related scenarios, such as generating unique session tokens or tracking unique software instances

Conclusion

Let's highlight, what we have learnt in this articles:

  • UUIDs, are 128-bit identifiers, and are designed for global uniqueness. They leverage algorithms that includes timestamps, machine identifiers, and randomness

  • They are represented as 32-character strings of hexadecimal digits and follow a distinctive structure, dividing into sections such as "8-4-4-4-12"

  • UUIDs widely used as primary keys in databases, facilitators of distributed systems, and unique identifiers in web development and security contexts

If you like my work, subscribe to my newsletter to never miss an update. Also, do support me by liking, commenting and sharing the article. These small things, keep me motivated to contribute such content 😌.

Did you find this article valuable?

Support codersk36 by becoming a sponsor. Any amount is appreciated!