In our life, ID is actually inseparable from our life.
ID card number, QQ, mobile phone number, bank card number, student ID number, even the number lying on your hard disk.
These ID marks are so important that every background programmer has to think about this problem? What are the advantages and disadvantages?
This article takes you to learn several common ID generation strategies in simple terms.
Due to space priority, it is recommended to read the following article.
Distributed ID generation requirements
UUID strategy explanation
Random generation strategy
Explanation of snowflake algorithm
Open source tools
ID is a common ID implementation strategy for Java design.
So that you can use it out of the box in daily development and enjoy the happiness of leaving work early~
For ID generation, all background systems must face the problem, distributed ID generation is also a very common requirement.
Recently, the code written by my colleagues, in multiple machines and issued a serial number conflict.
I think Id strategies should be aggregated into a toolkit instead of building wheels every time. Sometimes there are problems.
- Minimalist API, a line of code to do everything
- Built in a variety of ID generation strategies, there is always one for you
- The jar package is only 13K
<dependency> <groupId>com.github.houbb</groupId> <artifactId>id</artifactId> <version>0.0.2</version> </dependency>
final String snowflake = IdHelper.snowflake(); System.out.println(snowflake);
Built in method
All IDS can be accessed through the
|6||local()||Starting from 0, gradually add 1 to return the ID|
-  snowflake customization + code optimization
-  introduce comb algorithm
- ] compatibility of other open source IDS
-  ID generation based on common databases
-  ID generation based on redis