Snowflake ID

Snowflake IDs, or snowflakes, are a form of unique identifier used in distributed computing. The format was created by Twitter and is used for the IDs of tweets. The format has been adopted by other companies, including Discord, and Instagram, which uses a modified version.

1356683507933380608
Snowflake ID
Other namesTwitter Snowflake

Components of a snowflake identifier in binary

Format

Snowflakes are 64 bits. The first 41 bits are a timestamp, representing milliseconds since the chosen epoch. The next 10 bits represent a machine ID, preventing clashes. The remaining 12 bits represent a per-machine sequence number, to allow creation of multiple snowflakes in the same millisecond.[1]

Because snowflakes are 64 bits, which is more than JavaScript supports as an integer, they must be processed as a string, even though they are entirely numeric.[2]

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, and vice versa. This can be used to get snowflakes (and their associated objects) that were created before or after a particular date.[3]

Usage

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

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]

See also

References

  1. "twitter-archive/snowflake at b3f6a3c6ca". October 1, 2012. Retrieved January 18, 2021.
  2. Siegler, MG (October 19, 2010). "Twitter's Snowflake Project To Update Tweet IDs Really Is More Like A Blizzard Now". TechCrunch. Retrieved January 18, 2021.
  3. "API Reference". Discord Developer Portal. Discord. Retrieved January 18, 2021.
  4. King, Ryan (June 1, 2010). "Announcing Snowflake". blog.twitter.com. Twitter. Retrieved January 18, 2021.
  5. 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.
  6. "Twitter IDs". Twitter Developer. Twitter. Retrieved January 20, 2021.
  7. "Sharding & IDs at Instagram". Instagram Engineering. May 2, 2016. Retrieved January 18, 2021.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.