# Snowflake ID

Key: `technology.identifier.snowflake_id`

Twitter/Discord-style snowflake identifier. A 17-20 digit integer encoding a millisecond timestamp, worker ID, and sequence number.

Page: <https://meridian.online/docs/projects/finetype/types/technology/identifier/snowflake_id>

Samples: `175928847299117063`, `1234567890123456789`, `80351110224678912`

## Background

### Origin

The snowflake ID format was created by Twitter and is used for the IDs of tweets.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) The format was first announced by Twitter in June 2010.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) The name snowflake ID comes from the popular belief that every snowflake has a unique structure.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) Twitter's Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees.[[2]](https://github.com/twitter-archive/snowflake) Twitter's 2010 Snowflake README says the company needed a new way to generate id numbers as it moved away from MySQL towards Cassandra.[[3]](https://github.com/twitter-archive/snowflake/tree/snowflake-2010)

The 2010 README requires that machines generating ids should not have to coordinate with each other, for high availability within and across data centers.[[3]](https://github.com/twitter-archive/snowflake/tree/snowflake-2010) The 2010 README also requires the ids to be sortable without loading the full objects they represent.[[3]](https://github.com/twitter-archive/snowflake/tree/snowflake-2010) Twitter needed to keep the ids under 64 bits, according to the 2010 README.[[3]](https://github.com/twitter-archive/snowflake/tree/snowflake-2010)

In Twitter's design, an id is composed of a 41-bit millisecond timestamp, a 10-bit configured machine id and a 12-bit sequence number.[[3]](https://github.com/twitter-archive/snowflake/tree/snowflake-2010) The 2010 README says the 41-bit time field, at millisecond precision with a custom epoch, gives 69 years.[[3]](https://github.com/twitter-archive/snowflake/tree/snowflake-2010) The 12-bit sequence number rolls over every 4096 per machine.[[3]](https://github.com/twitter-archive/snowflake/tree/snowflake-2010) The highest-order bit of a snowflake is always 0.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) Only 63 bits of a snowflake are variable, so that a non-negative number can be processed readily as a 64-bit signed integer.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) Twitter's Scala IdWorker sets its custom epoch, twepoch, to 1288834974657.[[4]](https://raw.githubusercontent.com/twitter-archive/snowflake/snowflake-2010/src/main/scala/com/twitter/service/snowflake/IdWorker.scala) The archived Scala library splits the 10-bit machine ID into a 5-bit data center ID and a 5-bit worker ID.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID)[[4]](https://raw.githubusercontent.com/twitter-archive/snowflake/snowflake-2010/src/main/scala/com/twitter/service/snowflake/IdWorker.scala)

### Use

X uses snowflake IDs for tweets, direct messages, users, lists and all other objects available over the API.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) Instagram uses a modified version of the format, with 41 bits for a timestamp and 13 bits for a shard ID.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) Vanilla Mastodon entity IDs are generated as integers, usually using a variant of Snowflake ID.[[5]](https://docs.joinmastodon.org/api/guidelines/) Treat the worker and sequence fields as internal detail; they are useful for spotting duplicates, not for analysis. (Meridian's view)

Discord returns snowflakes as strings in its HTTP API to prevent integer overflows in some languages.[[6]](https://docs.discord.com/developers/reference) JavaScript's Number.MAX\_SAFE\_INTEGER is 9007199254740991.[[7]](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) Double precision floating point can only safely represent integers between -(2^53 - 1) and 2^53 - 1, according to MDN.[[7]](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) Load snowflake columns as text or as 64-bit integers, never as floating-point numbers, and be wary of any spreadsheet or JSON tool that reads numbers as doubles. (Meridian's view) If two IDs that should differ come out identical after an import, suspect a float conversion first. (Meridian's view)

Snowflakes are sortable by time, because they are based on the time they were created.[[1]](https://en.wikipedia.org/wiki/Snowflake_ID) When snowflakes are stored as text, sort by length before sorting lexically, or cast to a 64-bit integer first. (Meridian's view) Read the order of snowflakes as approximate creation order, not as an exact sequence of events across machines. (Meridian's view)

### Where you'll meet it

Discord's API reference says Discord utilizes Twitter's snowflake format for uniquely identifiable descriptors.[[6]](https://docs.discord.com/developers/reference)

## Sources

1. [Snowflake ID](https://en.wikipedia.org/wiki/Snowflake_ID) — secondary source
2. [GitHub - twitter-archive/snowflake: Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees. · GitHub](https://github.com/twitter-archive/snowflake) — documentation
3. [GitHub - twitter-archive/snowflake at snowflake-2010 · GitHub](https://github.com/twitter-archive/snowflake/tree/snowflake-2010) — documentation
4. [IdWorker.scala](https://raw.githubusercontent.com/twitter-archive/snowflake/snowflake-2010/src/main/scala/com/twitter/service/snowflake/IdWorker.scala) — documentation
5. [Guidelines and best practices](https://docs.joinmastodon.org/api/guidelines/) — documentation
6. [API Reference](https://docs.discord.com/developers/reference) — organisation
7. [Number.MAX\_SAFE\_INTEGER - JavaScript \| MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) — documentation
