Global ID Generation in Distributed System

This is the post excerpt.

  1. Use Db Auto Generate ID
    pros : unique and in order.
    cons : not working in multiple Db instance.

  1. Use Db Auto Generate ID with increasement N (for example 3 for 3 machines)
    the number of DB instance = increasement unit of the ID
    Db1 (0,3,6,9,….) , Db2(1,4,7,10…), Db3 (2,5,8,11…)
    pros :
    numbers are in order .
    works fine with a fixed number of DB instance .
    cons :not possible to add DB instance .

  2. GUID
    pros : extensibility .
    cons :
    numbers are not in order .
    need more storage ,length is long so query slow .

  3. snowflake algorithm

Id is composed of:
-time – 41 bits (millisecond precision)
-configured instance id – 10 bits – gives us up to 1024 instances
-sequence number – 12 bits – usually 0, incremented when more than one id is requested in the same millisecond and reset to 0 when the clock ticks forward. Rolls over every 4096 per machine.
The generator has protection mechanism for sequence roll over in the same millisecond.

4million ID can be generated per second

Author: lanliang


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s