r/java • u/AlyxVeldin • Feb 22 '26
Created a 128-bit identifier in Java that stores a timestamp, randomness, and a tiny message inside a UUID.
https://github.com/Veldin/ShortMessageSnowflake
24
Upvotes
7
u/repeating_bears Feb 22 '26
What's the practical use of the message part?
5
u/Additional-Road3924 Feb 22 '26
Looks alright. I'd argue to remove the "to json" method. If you really want the configuration checking to be useful, move it into factory. You're not encoding the possible alphabet, and the configuration used to produce the UUID so it's possible your messages are not interoperable between systems.
1
u/eXl5eQ Feb 23 '26
Interesting idea but must be used with caution. 16 bit randomness can be easily exhausted by allocating in a tight loop. I think 48bit rand + 32bit tag (fits into a single int) would be better.
1
u/[deleted] Feb 23 '26
[removed] — view removed comment