Skip to content

Unique IDS

Santhosh Kumar edited this page May 21, 2024 · 1 revision

https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c

  • 41 bits for millisecond since the custom epoch (41 years worth of id)
  • 13 bits for the shard number
  • 10 bits for auto-incrementing sequence number

1024 IDs, per shard, per millisecond

Snowflake ID

The ID as a whole is a 63 bit integer stored in an int64

  • 41 bits for millisecond since the custom epoch (41 years worth of id)
  • 10 bits for the node id
  • 12 bits for auto-incrementing sequence number

4096 IDs, per node, per millisecond

UUID vs ULID

  • It isn't the most character efficient way of encoding 128 bits
  • UUID v1/v2 is impractical in many environments, as it requires access to a unique, stable MAC address
  • UUID v3/v5 requires a unique seed and produces randomly distributed IDs, which can cause fragmentation in many data structures
  • UUID v4 provides no other information than randomness which can cause fragmentation in many data structures

A ULID however:

  • Is compatible with UUID/GUID's
  • 1.21e+24 unique ULIDs per millisecond (1,208,925,819,614,629,174,706,176 to be exact)
  • Lexicographically sortable
  • Canonically encoded as a 26 character string, as opposed to the 36 character UUID
  • Uses Crockford's base32 for better efficiency and readability (5 bits per character)
  • Case insensitive
  • No special characters (URL safe)
  • Monotonic sort order (correctly detects and handles the same millisecond)

Give Pricing Plans based on the "CF-IPCountry"

DBStats, HEadStatus, WalReplayStatus

Clone this wiki locally