Order number generation

How to generate a unique order number under high concurrency
Scheme 1:
  If there is no concurrency, the order number is only generated in one thread, and the timestamps of different orders are different.   
  Timestamp + random number (self-incrementing number) distinguishes
   the order if there is concurrency, and The order number generates multiple processes on the same host. As long as the process ID is added to the serial number, the order number can be guaranteed to be unique.
     If there is concurrency, and the order is in different hosts, adding a number that can be distinguished by the IP address CPU serial number to the serial number can be guaranteed to be unique.

Option 2:
       Timestamp + User ID + Random Number + Optimistic Lock

Option 3:
  You can use the atomic increment of redis to make a high-availability cluster.
     Redis itself has the function of generating serial numbers, and uses a persistent thread-safe

solution Option 4:
   Java self The order number of the UUID

XX with the belt: XXCN201700000000
The order number of YY:
YYCN201700000000 The year should be changed according to the real year, and then once the year is updated, the last 8 digits will start from 00000000.

In fact, it can be done through redis, but this requirement is also strange, because I am afraid that people will not know how many orders the system has?
In the case of postgrel, sequences can be used.
You can use the atomic increment of redis to make a high-availability cluster

http://m.blog.csdn.net/shuaizai88/article/details/53566425

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326523045&siteId=291194637