FinTx is an open source group focus on financial technologies.
fintx-identifier is for generating unique id in high performance and distribution environment. It extends the mongodb's ObjectId that using full MAC address to prevent the duplicated Id. It does not depend on the seeds like snowflake id generator. It can generate both 20 charachers base64 URL safe id (recommend) and 30 characters hex character id. Both id characters are in sequence that not random.
Consists of 15 bytes, divided as follows:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
time | machine | pid | counter |
- ProcessId on os could not bigger then 65535 (the default max value in most linux OS).
- Only in one bundle of same JVM when using OSGI.
- Id requirement could not more then about 16777215 per second per JVM.
- Maybe it will generate duplicated id every (2^32 - 1)/(60 * 60 * 24 * 365)โ136.19 years with same machine and same process(no possible).
This is something that you get for free just by adding the following dependency inside your project:
<dependency>
<groupId>org.fintx</groupId>
<artifactId>fintx-identifer</artifactId>
<version>${latest.version></version>
</dependency>
- Get a 20 characters length unique id.
String id = UniqueId.get().toBase64String();
- Parse id to get timestamp, machine identifier (physical MAC address), process identifier, counter number.
UniqueId uniqueId = UniqueId.fromBase64String(id);
long timestamp = uniqueId.getTimestamp();
long machineId = uniqueId.getMachineIdentifier();
int processId = uniqueId.getProcessIdentifier();
long counter = uniqueId.getCounter();
[1] FinTx https://www.fintx.org/
[2] Maven https://maven.apache.org/