Skip to content

Distributed understandable unique id generator with high performance and not depends on seeds like snowflake.

License

Notifications You must be signed in to change notification settings

fintx/fintx-identifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FinTx Identifier Generator

Maven Central GitHub release Apache 2 Join the chat at https://gitter.im/fintx/fintx-identifier Build Status Coverage Status Dependency Status

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 layout
01234567891011121314
timemachinepidcounter

Limitations

  1. ProcessId on os could not bigger then 65535 (the default max value in most linux OS).
  2. Only in one bundle of same JVM when using OSGI.
  3. Id requirement could not more then about 16777215 per second per JVM.
  4. 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

  1. Get a 20 characters length unique id.
String id = UniqueId.get().toBase64String();
  1. 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/