Today I learned that there are 8 versions of UUID!
I was vaguely aware that there were some older versions that aren’t recommended but just this past May the RFC was approved that added versions 6, 7, and 8.
Basically, v4 is a good default if you just need a good unguessable random ID. For javascript, this is now built into browsers via crypto.randomUUID()
— or in dotnet with Guid.NewGuid()
.
But v7 is an exciting new option because it’s time-based so the UUIDs are sortable based on when it was created and you can even extract the timestamp if you want. This also apparently makes it better as a database key.
The uuid npm package just added support for v7 if you need it in javascript. For C#, v7 support is coming in dotnet 9.
This is a nice overview of the different versions if you want to read more.