Snowflake ID
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. 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
Snowflakes are 64 bits in binary. 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.Snowflakes are sortable by time, because they are based on the time they were created. Additionally, the time a snowflake was created can be calculated from the snowflake. This can be used to get snowflakes that were created before or after a particular date.
Example
A tweet produced by @Wikipedia in February 2025 has the snowflake ID.The number may be converted to binary as, with pipe symbols denoting the three parts of the ID.
- The first 41 bits convert to decimal as. Add the value to the X Epoch of , the Unix time of the tweet is therefore : February 10, 2025 13:34:39.256 UTC.
- The middle 10 bits are the machine ID.
- The last 12 bits decode to, meaning this tweet is the 322'nd snowflake processed this millisecond.
Usage
- X uses snowflake IDs for tweets, direct messages, users, lists, and all other objects available over the API.
- 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.
- Discord also uses snowflakes, with their epoch set to, which translates to the zeroth second of the year 2015.
- 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.
- 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.