simpleflake
UUID
Our great sponsors
simpleflake | UUID | |
---|---|---|
1 | 9 | |
178 | 12,321 | |
0.0% | - | |
0.0 | 7.5 | |
over 4 years ago | 3 days ago | |
Python | PHP | |
GNU General Public License v3.0 or later | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
simpleflake
-
Sortable Collision-Free UUIDs
I've used something very similar in the past, called SimpleFlake[0], which is essentially a 64 bit version with the same principles. I've used it in Lisp, C, C++, Clojure, Python, and Rust. It's conceptually simple, and fits in a 64bit int, which is natively available in a lot of databases.
[0] SimpleFlake - https://github.com/SawdustSoftware/simpleflake/blob/f2b51f76...
UUID
-
Weekly help thread
I'd recommend using either Ramsey/uuid or generating a random number using random_bytes(32) then compressing it. 32 bits of randomness should be sufficient for most programs.
-
eli5 With billions and billions of people over time, how can fingerprints be unique to each person. With the small amount of space, wouldn’t they eventually have to repeat the pattern?
Of course, theoretical math and applied math often work out differently. Here's a thread with a guy claiming his team's software is running into "Several hundred [UUID] collisions per day"
-
weird php results microtime/hrtime
Or just use a library.
-
UUIDs are a wonderful invention
I'll leave this here https://github.com/ramsey/uuid/issues/80
-
What are types of bugs that only show up after thousands or millions of times of the code being run.
Not really in the realm of “thousands” of runs, but UUID collisions are possible and have been observed multiple times after only 1 million generations due to unknown reasons.
- Generating unique key code using PHP
-
Sortable Collision-Free UUIDs
There's also the risk of bad randomness sources and/or bugs.
One popular UUID library got a bug report stating: "We are generating about 1M UUID4 a day, and we are getting several hundred collisions a day". And so they were; turned out to be a bug/weird interaction between the OpenSSL library they were using for randomness and forking. (Details here, although it was all fixed years ago of course: https://github.com/ramsey/uuid/issues/80)
On paper, you should never, ever, ever see a collision when generating a mere million v4 UUIDs a day, much less hundreds of collisions. But that doesn't mean it can't happen!
This is also an interesting bit of analysis; comes from a company that processed a lot of UUIDs generated in browsers, checked, and discovered about 5 collisions per million UUIDs. Again, not what you'd naively expect! (Turned out to be mostly driven by misbehaving crawlers.) https://medium.com/teads-engineering/generating-uuids-at-sca...
-
Things You Should Do Now
just make sure you have everything configured correctly on your system if using UUIDs:
https://github.com/ramsey/uuid/issues/80
In the types of systems that need UUIDs there is probably no easy way to check for collisions. The prospect of mystery data corruption with no ability to trace it down frightens the hell out of me.
The only reason that issue was reported is because someone was actually doing the collision checking. That's not going to be the norm in UUID systems. Think about it.
-
A UUID can have so many combinations that UUIDs are effectively unique. But it's possible to generate the same one twice, however small the chance. Is it best practice to take this chance into account, checking to be sure you haven't used it?
In theory the risk of collision is so small it can be written off, but implementations can have bugs.
What are some alternatives?
uuid - Generate RFC-compliant UUIDs in JavaScript
cuid - Collision-resistant ids optimized for horizontal scaling and performance.
tsid-creator - A Java library for generating Time-Sorted Unique Identifiers (TSID).
php-ulid - A PHP port of alizain/ulid with some minor improvements.
ksuid - Java implementation of K-Sortable Globally Unique IDs
ulid - Universally Unique Lexicographically Sortable Identifier (ULID) in Python 3
spec - The canonical spec for ulid
spec - The Score Specification provides a developer-centric and platform-agnostic Workload specification to improve developer productivity and experience. It eliminates configuration inconsistencies between environments.
Slugify - Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.
Device Detector - The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.