1. Algorithm Introduction
Reference http://www.lanindex.com/twitter-snowflake%EF%BC%8C64%E4%BD%8D%E8%87%AA%E5%A2%9Eid%E7%AE%97%E6%B3%95%E8%AF%A6%E8%A7%A3/
The background of the Twitter-snowflake algorithm is quite simple, in order to meet the Twitter request for tens of thousands of messages per second, each message must be assigned a unique ID, these IDs also need some general order (convenient for clients to sort), And the IDs generated by different machines in the distributed system must be different.
Snowflake Algorithm Core
Combine timestamps , work machine IDs, serial numbers
2. Function realization
Based on the Beego framework
Code See: Https://github.com/mtour/restsnowflake
Personally think this algorithm is very ingenious design, can be conveniently recorded in chronological order, 10-bit machine ID, enough to support 1024 nodes
Get the self-increment ID via the rest interface (Twitter snowflake algorithm)