Edge Rewrite
// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a40d563b2e2222ce

Jump to content

Snowflake ID

From Wikipedia, the free encyclopedia

2103281343013060608
Snowflake ID
Other namesTwitter Snowflake
X Snowflake
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 X (formerly Twitter) 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.

Format

[edit]

A snowflake is composed of 64 bits:

  • The highest-order bit is always 0.
  • The next 41 bits encode a timestamp, representing milliseconds since the chosen epoch.
  • The next 10 bits represent a machine ID, preventing clashes.
  • The next 12 more bits represent a per-machine sequence number, to allow creation of multiple snowflakes in the same millisecond.

Only 63 bits are variable, so that a non-negative number can be processed readily as a 64-bit signed integer; the final number is generally serialized textually as a decimal number.[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 0 1 2 3
Octet Bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
0 0 0 Timestamp - first 31 bits
4 32 Timestamp - last 10 bits Machine ID Machine Sequence Number

Example

[edit]

A tweet produced by @Wikipedia in February 2025[4] has the snowflake ID 1888944671579078978. The number may be converted to binary as 0001 1010 0011 0110 1110 0001 0010 1011 1011 0101 11 | 01 0110 1000 | 0001 0100 0010, with pipe symbols denoting the three parts of the ID.

  • The first 41 (+ 1 top zero bit) bits convert to decimal as 450359504599. Add the value to the X Epoch of 1288834974657 (in Unix time milliseconds),[5] the Unix time of the tweet is therefore 1739194479256: February 10, 2025 13:34:39.256 UTC.
  • The middle 10 bits 01 0110 1000 are the machine ID.
  • The last 12 bits 0001 0100 0010 decode to 322, meaning this tweet is the 322'nd snowflake processed this millisecond.

Usage

[edit]

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]

  • X (formerly Twitter) uses snowflake IDs for tweets, direct messages, users, lists, and all other objects available over the API.[7]
  • The 10-bit machine ID field can be further split into sub-fields by a given implementation. For example, the archived version of the original Twitter snowflake library in Scala splits it into a 5-bit data center ID and a 5-bit worker ID.[8]
  • Discord also uses snowflakes, with their epoch set to 1420070400000, which translates to the zeroth 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.[9]
  • Mastodon's modified format has 48 bits for a millisecond-level timestamp, as it uses the UNIX epoch. The remaining 16 bits are for sequence data.[10]

See also

[edit]

References

[edit]
  1. 1 2 King, Ryan (June 1, 2010). "Announcing Snowflake". blog.twitter.com. Twitter. Archived from the original on May 8, 2021. Retrieved January 18, 2021.
  2. 1 2 "twitter-archive/snowflake at b3f6a3c6ca". GitHub. October 1, 2012. Archived from the original on June 22, 2021. Retrieved January 18, 2021.
  3. 1 2 "API Reference". Discord Developer Portal. Discord. Archived from the original on August 31, 2022. Retrieved January 18, 2021.
  4. ↑ @Wikipedia (February 10, 2025). "Wikipedia is a free encyclopedia written and maintained by a community of nearly 260,000 volunteers" (Tweet) – via X (formerly Twitter).
  5. ↑ "2019-08-03: TweetedAt: Finding Tweet Timestamps for Pre and Post Snowflake Tweet IDs". 2019-08-03. Archived from the original on June 17, 2022. Retrieved July 1, 2022.
  6. ↑ Siegler, MG (October 12, 2010). "Tweet IDs About To Get Jumbled In A Blizzard As Snowflake Is Set To Roll Live". TechCrunch. Archived from the original on October 19, 2022. Retrieved January 18, 2021.
  7. ↑ "Twitter IDs". Twitter Developer. Twitter. Archived from the original on September 1, 2022. Retrieved January 20, 2021.
  8. ↑ Source Code twitter-archive/snowflake, Twitter, August 14, 2010, archived from the original on December 31, 2025, retrieved May 24, 2025
  9. ↑ "Sharding & IDs at Instagram". Instagram Engineering. May 2, 2016. Archived from the original on January 12, 2021. Retrieved January 18, 2021.
  10. ↑ Source Code mastodon/mastodon, Mastodon, November 11, 2022, archived from the original on November 11, 2022, retrieved November 11, 2022
[edit]