- Use Db Auto Generate ID
pros : unique and in order.
cons : not working in multiple Db instance.
- 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…)
numbers are in order .
works fine with a fixed number of DB instance .
cons :not possible to add DB instance .
pros : extensibility .
numbers are not in order .
need more storage ,length is long so query slow .
- 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