Interview chain gun series (XI): talk about your design distributed ID

  1. Distributed ID talk about your design
    we use Snowflake algorithm generates a number of 64bit, 64bit is divided into a plurality of segments, each represent a time stamp, machine code, serial number.
    • 41 time series (to the millisecond, the length 41 may be used 69 years).
    • 10 machine identification (10 bits up to the length of the deployment of support nodes 1024).
    • 12-bit sequence number counter (12-bit sequence number counter for each node to support the generation ID number 4096 per millisecond).
      advantage:
    • Time stamp at a high level, since the increase in the low sequence, the entire ID is a trend of increasing, according to the ordered time.
    • High performance, can generate several million ID per second.
    • Can be flexibly adjusted bit bit divided according to their business needs, to meet different needs.
  2. Snowflake algorithm What are the disadvantages?
    It algorithms rely machine clock, the clock if the call-back machine, cause repeated generation ID. Although the single is increasing, but in a distributed environment, the clocks on each machine can not be completely synchronized, sometimes not the case there will be increasing globally.

  3. UUID is not it more simply, why not?
    UUID 128 is 16 bytes long number, a string of 36 bytes to represent, comprising UUID algorithm specification defines MAC address, time stamp, the name space (the Namespace), random or pseudo-random number sequence and other elements. UUID is too long, and there is no order, suitable for a database index field.

  4. ID Snowflake algorithm is too long, there is no shorter scheme
    may be employed based on atomic increment INCR Redis, such as order number from day + = growth number.

  5. What is the disadvantage of using Redis program?
    • If the system does not Redis, also we need to be introduced to increase the complexity of the system.
    • Require coding and configuration workload is relatively large.

Reference (excerpt of the text portion of the original author belongs Rights):

https://blog.csdn.net/hl_java/article/details/78462283
https://www.jianshu.com/p/2456c737aebb

Guess you like

Origin www.cnblogs.com/xiaoyangjia/p/11607361.html