liz3 / snowflake

Id system used by discord originally from twitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Snowflake

C implementation of a simple socket server replying with unique ids based on Twitters snowflake system. This might be used later in our services should it become necessary.

Instance

Binary

111111111111111111111111111111111111111111 11111 11111 111111111111
64                                         22    17    12          0

Left to right:

  • first 42 bits: amount of ms since epoch (start of 2015), retrieval: (value >> 22) + 1420070400000
  • next 5 bits: region id(defined during compile time), retrieval: (value & 0x3E0000) >> 17
  • next 5 bits: worker id(defined during compile time), retrieval: (value & 0x1F000) >> 12
  • last 12 bits: For every ID that is generated on that process, this number is incremented, retrieval: value & 0xFFF

About

Id system used by discord originally from twitter


Languages

Language:C 59.9%Language:JavaScript 33.9%Language:Dockerfile 4.4%Language:CMake 1.8%