FinTx Identifier Generator
FinTx[1]
What's is FinTx?
FinTx is an open source group focus on financial technologies.
What's is fintx-identifier
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.
Structure
Consists of 15 bytes, divided as follows:
UniqueId layout0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
time | machine | pid | counter |
Limitations
- 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).
Using
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>
Example
- 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/