Share
Embed
ULID vs UUID
ULID, UUID v7 (Time-Based IDs) and UUID v4 (Random Ids) offers completely different characteristics.
Learn about the data layout and when to prefer one or the other based on your type of database and behaviour you want to obtain.
Learn how ULID can cause hotspots in distributed databases, and how UUID v4 can cause fragmentation and increased disk I/O in traditional B+Tree based databases.
Matteo Bertozzi
August 13, 2023
Transcript
40 slides
-
ULID 01H6CEMR6FXX5BCY6G0PE02VRA UUID vs 587f93d8-7b4d-42df-9d83-5832a7c02947 Unix epoch 48bits Random 80bits
4bits Version 2bits Variant 12bits 62bits 48bits -
UUID ULID (16-bytes) 128-bits (16-bytes) 128-bits 128-bit (16-bytes) block of
data 128-bit (16-bytes) block of data Universal Unique Identifier Universally Unique Lexicographically Sortable Identifier -
UUID 4bits Version 2bits Variant 128-bit (16-bytes) block of data
128-bit (16-bytes) block of data ULID 6-bit reserved for the version and variant Universal Unique Identifier Universally Unique Lexicographically Sortable Identifier -
UUID v4 4bits Version 2bits Variant Random 12bits Random 62bits
Random 48bits 4 128-bit (16-bytes) block of data 128-bit (16-bytes) block of data ULID 6-bit reserved for the version and variant 122-bit Random data, Good distribution Universal Unique Identifier Universally Unique Lexicographically Sortable Identifier -
ULID Unix epoch (Big Endian) 48bits UUID v4 4bits Version
2bits Variant Random 12bits Random 62bits Random 48bits 4 128-bit (16-bytes) block of data 6-bit reserved for the version and variant 122-bit Random data, Good distribution 48-bit Timestamp, Big-Endian encoded 128-bit (16-bytes) block of data Universal Unique Identifier Universally Unique Lexicographically Sortable Identifier -
ULID Unix epoch (Big Endian) 48bits UUID v4 4bits Version
2bits Variant Random 12bits Random 62bits Random 48bits 4 128-bit (16-bytes) block of data 6-bit reserved for the version and variant 122-bit Random data, Good distribution Lexicographically sortable, time-based locality 48-bit Timestamp, Big-Endian encoded 128-bit (16-bytes) block of data Universal Unique Identifier Universally Unique Lexicographically Sortable Identifier -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID v4
4bits Version 2bits Variant Random 12bits Random 62bits Random 48bits 4 128-bit (16-bytes) block of data 128-bit (16-bytes) block of data 6-bit reserved for the version and variant 122-bit Random data, Good distribution Lexicographically sortable, time-based locality 48-bit Timestamp, Big-Endian encoded Universal Unique Identifier Universally Unique Lexicographically Sortable Identifier -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID v4
4bits Version 2bits Variant Random 12bits Random 62bits Random 48bits 4 4bits Version 2bits Variant Random 12bits Random 62bits Unix epoch (Big Endian) 48bits 7 UUID v7 128-bit (16-bytes) block of data Lexicographically sortable, time-based locality 48-bit Timestamp, Big-Endian encoded 128-bit (16-bytes) block of data 6-bit reserved for the version and variant 122-bit Random data, Good distribution Universal Unique Identifier Universally Unique Lexicographically Sortable Identifier -
Time-Based Ids Random-Based Ids UUIDv4 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6
e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution NanoId Cuid2 -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d efe25407-e91b-4b59-8048-64833b85c7aa
3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 01H6YGDAFF12Y7KEZBAPAZRF6A 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d
efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 01H6YGDAFF12Y7KEZBAPAZRF6A 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d
efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 01H6YGDAFF12Y7KEZBAPAZRF6A 01H6YGDAJKAYX4K1XJ2WYVNCVQ (+100ms)
2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 01H6YGDAFF12Y7KEZBAPAZRF6A 01H6YGDAJKAYX4K1XJ2WYVNCVQ (+100ms)
01H6YGDANQCEWNZC5DMSGRV46J (+200ms) 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 01H6YGDAFF12Y7KEZBAPAZRF6A 01H6YGDAJKAYX4K1XJ2WYVNCVQ (+100ms)
01H6YGDANQCEWNZC5DMSGRV46J (+200ms) 01H6YGZMDFKFXS7M47DW956NWW (+10min) 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 01H6YGDAFF12Y7KEZBAPAZRF6A 01H6YGDAJKAYX4K1XJ2WYVNCVQ (+100ms)
01H6YGDANQCEWNZC5DMSGRV46J (+200ms) 01H6YGZMDFKFXS7M47DW956NWW (+10min) 01H6YGZMGKCY1MG4HM9TWHY2XN (+10min) 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7 01H6YGDAFF12Y7KEZBAPAZRF6A 01H6YGDAJKAYX4K1XJ2WYVNCVQ (+100ms)
01H6YGDANQCEWNZC5DMSGRV46J (+200ms) 01H6YGZMDFKFXS7M47DW956NWW (+10min) 01H6YGZMGKCY1MG4HM9TWHY2XN (+10min) 01H712T1FFXBJ919A0GSQRWMRZ (+24h) 2f52de59-4a7b-45eb-8d71-2df6aa950061 9f108a35-35af-4244-af86-c2222ffb475d efe25407-e91b-4b59-8048-64833b85c7aa 3f56beae-235f-472d-8b40-d80bff249fb9 ace3857f-6b92-483c-a18c-a7c7acd34ea6 e92ee082-4380-4b2e-b599-0bf32d5138ee Random Data Distribution Time-Based Data Locality NanoId Cuid2 Snowflake XID KSUID -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 Lexicographically sortable, time-based locality. -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 Lexicographically sortable, time-based locality. Do not require coordination to be generated, and can be generated offline. Do not require coordination to be generated, and can be generated offline. -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 Lexicographically sortable, time-based locality. Do not require coordination to be generated, and can be generated offline. Do not require coordination to be generated, and can be generated offline. up-to-date databases have UUID type support -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 Lexicographically sortable, time-based locality. Do not require coordination to be generated, and can be generated offline. Do not require coordination to be generated, and can be generated offline. up-to-date databases have UUID type support or BINARY(16) can be used (avoid text format for keys) BINARY(16) can be used (avoid text format for keys) -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 Lexicographically sortable, time-based locality. Do not require coordination to be generated, and can be generated offline. Do not require coordination to be generated, and can be generated offline. Opaque non-guessable IDs using the randomness of UUID v4 up-to-date databases have UUID type support or BINARY(16) can be used (avoid text format for keys) BINARY(16) can be used (avoid text format for keys) -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 Lexicographically sortable, time-based locality. Do not require coordination to be generated, and can be generated offline. Do not require coordination to be generated, and can be generated offline. Temporary non-secure Tokens: the client can check the timestamp for expiration. Opaque non-guessable IDs using the randomness of UUID v4 up-to-date databases have UUID type support or BINARY(16) can be used (avoid text format for keys) BINARY(16) can be used (avoid text format for keys) -
ULID Random 80bits Unix epoch (Big Endian) 48bits UUID 4bits
Version 2bits Variant 12bits 62bits 48bits Encoded as a 26 character string using Crockford's Base32 (5bit per character) 01H6YGDAFF12Y7KEZBAPAZRF6A Encoded as a 36 character string using Base16 (4bit per character) 71acfe9a-7fca-4d41-b0d7-1ba36d7343c0 Lexicographically sortable, time-based locality. Do not require coordination to be generated, and can be generated offline. Do not require coordination to be generated, and can be generated offline. Temporary non-secure Tokens: the client can check the timestamp for expiration. Event Id chronological order of events Opaque non-guessable IDs using the randomness of UUID v4 up-to-date databases have UUID type support or BINARY(16) can be used (avoid text format for keys) BINARY(16) can be used (avoid text format for keys) -
4bits Version 2bits Variant Random 12bits Random 62bits Random 48bits
4 Random 80bits Unix epoch (Big Endian) 48bits Time-Based Ids Random-Based Ids UUIDv4 ULID UUIDv7