Overview

  • UUIDv1 - UUIDv5: in RFC4122
  • Others: RFC 9562
  • 128 bits in size
  • Big endian

Fields

Variant Field

  • Determines the layout of the UUID
  • Could be called type field
  • consists of a variable number of the most significant bits of octet 8 of the UUID.

UUIDv1

image

  • Time Based UUID
  • Starting Time: Oct 15, 1568 (Gregorian Calendar) UTC
  • Clock sequence: avoid dups that arise when clock is set backwards in time
    • when time and node changes, it + 1 and mod
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           time_low                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           time_mid            |  ver  |       time_high       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|var|         clock_seq         |             node              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              node                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  • Problmes:
    • uncommon 100-nanosecond Gregorian Epoch (compared to Unix Timestamp)
    • timestamp is hard to be represented in ieee 754
    • Not time ordered, bad locality for B Tree

Tricks

  • Store in binary to save space and faster comparison on time