Snowflake ID

Last updated

1892917561008324608
Snowflake ID
Other namesTwitter Snowflake
X Snowflake
Components of a snowflake identifier in binary Snowflake-identifier.png
Components of a snowflake identifier in binary

Snowflake IDs, or snowflakes, are a form of unique identifier used in distributed computing. The format was created by Twitter (now X) and is used for the IDs of tweets. [1] It is popularly believed that every snowflake has a unique structure, so they took the name "snowflake ID". The format has been adopted by other companies, including Discord and Instagram. The Mastodon social network uses a modified version.

Contents

Format

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. [2]

Snowflakes are sortable by time, because they are based on the time they were created. [2] 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. [3]

Fixed header format
Offsets Octet 0123
Octet Bit 012345678910111213141516171819202122232425262728293031
000Timestamp - first 31 bits
432Timestamp - last 10 bitsMachine IDMachine Sequence Number

Example

A tweet produced by @Wikipedia in June 2022 [4] has the snowflake ID 1541815603606036480. The number may be converted to binary as 00 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.

Usage

The format was first announced by Twitter in June 2010. [1] Due to implementation challenges, they waited until later in the year to roll out the update. [6]

See also

References

  1. 1 2 King, Ryan (June 1, 2010). "Announcing Snowflake". blog.twitter.com. Twitter. Retrieved January 18, 2021.
  2. 1 2 "twitter-archive/snowflake at b3f6a3c6ca". GitHub . October 1, 2012. Retrieved January 18, 2021.
  3. 1 2 "API Reference". Discord Developer Portal. Discord. Retrieved January 18, 2021.
  4. @Wikipedia (June 28, 2022). "53 years ago today, members of the LGBTQI+ community began protesting in New York City in response to a police raid of the Stonewall Inn, a popular gay bar. The riots were a transformative event in the 20th century fight for LGBTQI+ rights in the US. (1/2)" (Tweet) via Twitter.
  5. "2019-08-03: TweetedAt: Finding Tweet Timestamps for Pre and Post Snowflake Tweet IDs". 2019-08-03.
  6. Siegler, MG (October 12, 2010). "Tweet IDs About To Get Jumbled In A Blizzard As Snowflake Is Set To Roll Live". TechCrunch. Retrieved January 18, 2021.
  7. "Twitter IDs". Twitter Developer. Twitter. Retrieved January 20, 2021.
  8. "Sharding & IDs at Instagram". Instagram Engineering. May 2, 2016. Retrieved January 18, 2021.
  9. Source Code mastodon/mastodon, Mastodon, November 11, 2022, retrieved November 11, 2022