Alot of people just use UUID just because they can without thinking whether they should or not. Personally, I don’t like UUIDs. I mean there are legit usecase for them however, seeing people just throw them just because they can, upsets me.

I think people are just using them as a duct tape for anywhere which requires a random value. Most people just slap UUID and call it unique. Some people use UUID in place which does not actually require UUID.

What is UUID

UUID, or Universally Unique Identifier, is a 128-bit number used to uniquely identify something. It’s often represented as a string of 32 hexadecimal digits separated by hyphens. While UUIDs are designed to be unique, there are certain aspects of them that make them less than ideal in certain situations.

The Problem with UUIDs

I believe that many people are using UUIDs as a quick fix for generating random values without considering whether it’s the most appropriate solution.

Overuse: Many developers simply slap a UUID onto something and call it unique without considering whether it’s truly necessary. This overuse can lead to unnecessary complexity and overhead in systems.

Unnecessary: In many cases, simpler solutions exist that could adequately serve the purpose without resorting to UUIDs. Options like using Math.random, crypto libraries for random number generation, or even sequential incrementing numbers in databases can often suffice.

Size: UUIDs are relatively large, consisting of 128 bits, which can be wasteful in terms of storage space and bandwidth, especially in situations where resources are limited.

Not URL Friendly: The format of UUIDs, with hyphens and hexadecimal characters, can make them less than ideal for use in URLs, where shorter, more human-readable identifiers are often preferred.

Collision Risks: While UUIDs are designed to be unique, the sheer number of UUIDs generated means that collisions are still possible, albeit rare. In situations where absolute uniqueness is critical, UUIDs may not be the best choice.

What could you use instead of UUID ?

Some usage of UUID can be replaced with the following alternatives:

  1. Normal Math.random: For scenarios where a simple random value is needed, Math.random function in JavaScript can be used.

  2. Using Crypto Random Library: Utilizing a cryptographic random library can provide a more secure and reliable source of randomness when needed.

  3. Database Generated IDs: In database-driven applications, auto-incremented primary keys can serve as unique identifiers without the need for UUIDs.

  4. Sequential Increment in Number: For cases where uniqueness is needed within a specific scope, sequential incrementing numbers can be sufficient.

Conclusion

In conclusion, while UUIDs serve their purpose in certain contexts, they are often overused and may not always be the most appropriate solution. Developers should carefully consider whether UUIDs are truly necessary for their use case and explore alternative methods of generating unique identifiers where applicable. By doing so, we can avoid unnecessary complexity and overhead in our systems.