Skip to content
Ahoo-WangPublic

About

Universal, flexible, high-performance distributed ID generator. | 通用、灵活、高性能的分布式 ID 生成器

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

652 stars

Watchers

10 watching

Forks

Latest commit

 

History

1,670 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

CosId Universal, flexible, high-performance distributed ID generator

License GitHub release Maven Central Version Codacy Badge codecov Integration Test Status AtomGit G-Star

中文文档 | English Document

Every replica of a service needs IDs (primary keys, order numbers, event ids) that never collide with those of the other replicas. CosId generates them inside your process, without a network call per ID, and does the coordination that keeps them unique: it leases a distinct machine id to every Snowflake instance from a store you already run, takes ranges of segment IDs ahead of time, and handles clocks that move backwards.

Generator ID Throughput on one instance (historical JMH) Pick it when
SegmentChainId long, near-sequential 127,439,148 ops/s You want short numeric keys or business numbers. The default segment mode
SnowflakeId long, time-ordered 4,096,000 ops/s (theoretical maximum) IDs should carry their creation time, with no store call after startup
CosIdGenerator String, 15 characters, time-ordered — You run very many instances (up to a million machine ids)

Stores: Redis, JDBC (MySQL, MariaDB, PostgreSQL), MongoDB, ZooKeeper, the CosId proxy, or your own. Integrations: Spring Boot, MyBatis, Spring Data JDBC, Jackson, ShardingSphere, Activiti, Flowable and Axon.

Version compatibility

CosId Spring Boot Java Branch
4.x 4.x 17+ main
3.x 4.x 17+ 3.x (maintenance)
2.x 3.x 17+ 2.x
1.x 2.x 8+ 1.x

Upgrading from 3.x: see MIGRATION-4.0.md.

Quick start

dependencies {
    implementation(platform("me.ahoo.cosid:cosid-bom:$cosidVersion"))
    implementation("me.ahoo.cosid:cosid-spring-boot-starter")
    implementation("me.ahoo.cosid:cosid-spring-redis") // or cosid-jdbc, cosid-mongo, cosid-zookeeper, cosid-proxy
    implementation("org.springframework.boot:spring-boot-starter-data-redis")
}
cosid:
  namespace: ${spring.application.name}
  segment:
    enabled: true
    distributor:
      type: redis
    provider:
      order:
        step: 100
long orderId = idGeneratorProvider.getRequired("order", IdGenerator.class).generate();

The Getting Started guide walks through it, including Snowflake IDs and Maven.

Documentation

The examples are runnable applications for Redis, ZooKeeper, the proxy and CosIdGenerator.

Performance

Historical JMH benchmarks on one development notebook (MacBook Pro M1, Redis on the same machine):

Throughput of SegmentChainId

Percentile sample of SegmentChainId

SegmentChainId is about five times as fast as Meituan Leaf's segment mode, see CosId VS Leaf.

Contributing

Bug reports, ideas and pull requests are welcome. Read CONTRIBUTING.md for the development setup, commit conventions, review and release process, and SECURITY.md to report a vulnerability privately. The planned work is in the roadmap.

Community Partners and Sponsors

About

Universal, flexible, high-performance distributed ID generator. | 通用、灵活、高性能的分布式 ID 生成器

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

652 stars

Watchers

10 watching

Forks

Releases

Packages

Used by

Contributors

Languages