So what is Snowflake?

Snowflake is a service used to generate unique IDs for objects within Twitter (Tweets, Direct Messages, Users, Collections, Lists etc.). These IDs are unique 64-bit unsigned integers, which are based on time, instead of being sequential. The full ID is composed of a timestamp, a worker number, and a sequence number. When consuming the API using JSON, it is important to always use the field id_str instead of id. This is due to the way Javascript and other languages that consume JSON evaluate large integers. If you come across a scenario where it doesn’t appear that id and id_str match, it’s due to your environment having already parsed the id integer, munging the number in the process. Read below for more information on how Twitter generates its ids.

最高位bit标记为不可用

前41bits是以微秒为单位的timestamp
接着10bits是事先配置好的机器ID。
最后12bits是累序列号,用来记录同毫秒内产生的不同id。
macheine id(10bits)标明最多只能有1024台机器/节点同时产生ID,sequence    
number(12bits)也标明1台机器1ms中最多产生4096个ID
imgs

2 对 “Twitter IDs snowflake”的想法;

发表回复

您的电子邮箱地址不会被公开。