✨ Magic UUIDs: Let’s Not Forget to Appreciate Them
🧠 Thought Experiment
Let’s imagine there’s a box. When you shake it, a number pops out. Then, you shake it again, and another, completely different number appears.
Now imagine giving this box to every person on Earth. No matter who shakes it, and no matter when – past, present, or future – it will always produce a number that has never appeared before.
In programming, that “box” is called a function, and the act of shaking it is a function call.
We’ve just described a UUID (Universally Unique Identifier) function, where each function call produces a unique value.
This simple concept is very (very) important and useful in computer science. In fact, modern systems and applications wouldn’t be able to function properly without it.
⚙️ Implementations
How do we implement the UUID function?
🏛️ Naive Approach: Fully Correct, Not Robust, Slow, Centralized, Impossible
We could create a large, central table to store all the values ever generated. Every time a new value is produced, we’d check the table to ensure the value hasn’t been generated before, regenerating it if necessary.
While this approach satisfies the uniqueness condition, it’s practically impossible to implement. We can’t realistically build a shared table accessible to every programmer across every network in the world. Simultaneous access would make it incredibly slow and inefficient.
Moreover, it’s a centralized solution—and centralization is something we try to avoid, both in computer science and in real life.
In computing, centralization leads to bottlenecks, single points of failure, and tight coupling – issues we try to avoid.
In real life, centralization is like relying on a single power plant to supply electricity to an entire city. If the plant fails, the whole city experiences a blackout. Similarly, in political systems, when decision-making is concentrated in one central authority, the system becomes unstable and vulnerable.
In short: we don’t like centralization.
🎲 Math-Based: Not Strictly Correct, but Fast and Decentralized
The random will help us. Imagine a vast list of all possible UUID values. On each function call, we simply pick a random one from that list.
This gives us a fast, decentralized approach that doesn’t rely on any central authority – at the cost of strict correctness.
That’s exactly how UUID version 4 works: it’s just a randomly chosen value from a very, very large space.
🔑 UUID v4 and Other Versions
There are 8 different versions of UUID. All of them are 16 bytes, or 128 bits, long. Version 4 (v4) reserves 6 bits for metadata, leaving 122 for randomness. That gives us 2122 ≈ 5.317 × 10³⁶ values.
How big is that number? Well, suppose all 8 billion people on Earth generated a billion UUIDs every second. It would still take around 21 billion years to generate all the values. So yes, it's a lot.
The probability of generating two identical UUIDs (called a collision) is extremely low, and it can be found using the birthday problem from the probability theory. For a 50% chance of a duplicate, you’d need ~2.71 × 10¹⁸ UUIDs. That’s equivalent to the entire world generating one UUID per second for nearly 11 years.
So, while UUID v4 isn’t strictly correct, it’s statistically “good enough”. The probability of a collision is so low that it can be ignored – just don’t worry about it and use UUIDv4!
Other UUID versions use other principles, e.g. v1 concatenates the host MAC address and the current timestamp, together with an incremental or random component to ensure uniqueness. However, this method can expose the time and place (computer) where the UUID was generated. It also relies on the MAC address being correctly assigned – something not always guaranteed, especially in virtual machines where MAC addresses can be manually configured or duplicated.
🎉 Applications and Fun
UUIDs are incredibly useful – having a way to uniquely identify something is a core concept in computer science. Think about it: every payment transaction needs a unique ID, every file on your phone or computer has an identifier, every email, message, and user account needs to be uniquely tracked.
Many people are impressed by the very simple yet very powerful concept – and have a lot of fun with it:
🌀 everyuuid.com
Someone actually built a site that lists every possible UUIDv4.
This produced some excellent reactions:
💬 “Wait… so every UUID I generate already exists??”
💬 “Hey, our UUIDs are public? Take these down or we’ll file a DMCA!”
{ad945cf8-77d6-401c-8dd7-d12345678910} {25826bef-d386-4030-9cea-4f2fc2abcdef} {b4dedc3f-053c-4287-a534-0ddfabababab}💬 “Now I’m stressed about running out of UUIDs. Thanks a lot.”
🌀 wasteaguid.info
This one burns a UUID on every page load. LOL.
It doesn’t use https – but please don’t worry, you’re just here to waste one more UUID!
Waste-A-GUID
75a4b683-c945-4993-a222-b0ff24a5658a
Thank you for making one less GUID available to the rest of us!
✨✨✨
UUIDs are one of those wonderful inventions, so next time you generate one, take a moment to appreciate it!