Home

Awesome

UUIDv7 in N languages

UUIDv7 is a 128-bit unique identifier like its older siblings, such as the widely used UUIDv4. But unlike v4, UUIDv7 is time-sortable with 1 ms precision. By combining the timestamp and the random parts, UUIDv7 becomes an excellent choice for record identifiers in databases, including distributed ones.

This repo provides zero-dependency UUIDv7 implementations in various languages. If you spot a bug — please submit a pull request. PRs for other languages are also welcome!

Structure

UUIDv7 looks like this when represented as a string:

0190163d-8694-739b-aea5-966c26f8ad91
└─timestamp─┘ │└─┤ │└───rand_b─────┘
             ver │var
              rand_a

The 128-bit value consists of several parts:

* In string representation, each symbol encodes 4 bits as a hex number, so the a in the example is 1010, where the first two bits are the fixed variant (10) and the next two are random. So the resulting hex number can be either 8 (1000), 9 (1001), a (1010) or b (1011).

See RFC 9652 for details.

Implementations

CC#C++ClojureCrystalDartEmacs LispElixirErlangF#GleamGoInkoJavaJavaScriptJuliaKotlinLuaNimNushellPerlPHPPascalPowerShellPythonRRacketRubyRustShellSQLSQL ServerSwiftTclVVimscriptZig

License

The Unlicense.