Snowflake ID - WikipediaSnowflake ID - Wikipedia

Snowflake ID - Wikipedia

Components of a snowflake identifier in binary
notion imagenotion image
Snowflakes are 64 bits in binary. (Only 63 are used to fit in a signed integer.) The first 41 bits are a timestamp, representing milliseconds since the chosen epoch. The next 10 bits represent a machine ID, preventing clashes. Twelve more bits represent a per-machine sequence number, to allow creation of multiple snowflakes in the same millisecond. The final number is generally serialized in decimal.[1]
Snowflakes are sortable by time, because they are based on the time they were created.[1] Additionally, the time a snowflake was created can be calculated from the snowflake. This can be used to get snowflakes (and their associated objects) that were created before or after a particular date.[2]
A tweet produced by @Wikipedia in June 2022 has the snowflake ID 1541815603606036480. The number may be converted to binary as 0b 0001 0101 0110 0101 1010 0001 0001 1111 0110 0010 00|01 0111 1010|0000 0000 0000, with pipe symbols denoting the three parts of the ID.
  • The middle 10 bits 01 0111 1010 are the machine ID.
  • The last 12 bits decode to all zero, meaning this tweet is the first tweet processed by the machine at the given millisecond.
The format was first announced by Twitter in June 2010.[4] Due to implementation challenges, they waited until later in the year to roll out the update.[5] Twitter uses snowflake IDs for tweets, direct messages, users, lists, and all other objects available over the API.[6]
Discord also uses snowflakes, with their epoch set to the first second of the year 2015.[2]
Instagram uses a modified version of the format, with 41 bits for a timestamp, 13 bits for a shard ID, and 10 bits for a sequence number.[7]