Skip to content
Back to search

CosId

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

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/Ahoo-Wang/CosId with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/Ahoo-Wang/CosId'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/ahoo-wang--cosid/badge.svg)](/listings/ahoo-wang--cosid)

HTML

<a href="/listings/ahoo-wang--cosid"><img src="/api/listings/ahoo-wang--cosid/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

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](https://cosid.ahoo.me/guide/getting-started.html) guide walks through it, including Snowflake IDs and Maven.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 142 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. <p align="center" style="text-align:center">
  2. <img width="300" src="./documentation/docs/public/logo.png"/>
  3. </p>
  4. # [CosId](https://cosid.ahoo.me/) Universal, flexible, high-performance distributed ID generator
  5. [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
  6. [![GitHub release](https://img.shields.io/github/release/Ahoo-Wang/CosId.svg)](https://github.com/Ahoo-Wang/CosId/releases)
  7. [![Maven Central Version](https://img.shields.io/maven-central/v/me.ahoo.cosid/cosid-core)](https://central.sonatype.com/artifact/me.ahoo.cosid/cosid-core)
  8. [![Codacy Badge](https://api.codacy.com/project/badge/Grade/dfd1d6237a1644409548ebfbca300dc1)](https://app.codacy.com/gh/Ahoo-Wang/CosId?utm_source=github.com&utm_medium=referral&utm_content=Ahoo-Wang/CosId&utm_campaign=Badge_Grade_Settings)
  9. [![codecov](https://codecov.io/gh/Ahoo-Wang/CosId/branch/main/graph/badge.svg?token=L0N51NB7ET)](https://codecov.io/gh/Ahoo-Wang/CosId)
  10. ![Integration Test Status](https://github.com/Ahoo-Wang/CosId/actions/workflows/integration-test.yml/badge.svg)
  11. <a href="https://atomgit.com/Ahoo-Wang/CosId"><img src="https://atomgit.com/Ahoo-Wang/CosId/star/new_badge.svg" alt="AtomGit G-Star" height="20px"/></a>
  12. > [中文文档](https://cosid.ahoo.me/zh/) | [English Document](https://cosid.ahoo.me/)
  13. > [!NOTE]
  14. > **CosId 5.0 is generally available.** The Java API, the `cosid.*` configuration and the storage formats and protocols
  15. > are stable: later 5.x releases only add to them. 4.x stays in maintenance; the offline
  16. > [`cosid-migration`](./migration/README.md) tool moves a deployment over.
  17. Every replica of a service needs ids (primary keys, order numbers, event ids) that never collide with those of the other
  18. replicas. *CosId* generates them inside your process, without a network call per id, and does the coordination that
  19. keeps them unique.
  20. **CosId 5** is a full rewrite with no backward compatibility. In it, **uniqueness depends on no clock**: a machine slot
  21. is leased as a time window, successive holders' windows never overlap, and the store itself keeps that rule. Clock
  22. skew, GC pauses and failovers cost availability, never uniqueness. Every strategy runs on one `CosIdRuntime`, and Spring
  23. Boot, cosid-server and plain Java start it the same way. The offline [`cosid-migration`](./migration/README.md) tool
  24. moves a 4.x deployment over.
  25. | Strategy | Id | Pick it when |
  26. |---|---|---|
  27. | `snowflake` | `long`, time-ordered (any `Layout`: ms or s, JS-safe 53 bits) | ids should carry their creation time, with no store call per id |
  28. | `segment` | `long`, dense, increasing per instance | you want short numeric keys; reservations size themselves to a time budget |
  29. | `periodic-segment` | per year / month / day (`20261027-000042`) | business numbers that restart each period |
  30. | `cosid80` | 80-bit text | you need more than 64 bits |
  31. | `uuidv7` | UUIDv7 (RFC 9562), time-ordered | you want standard UUIDs, with no machine, store nor lease |
  32. | `custom` | your own `long` generator | you have one, and want it served like the others |
  33. Stores: JDBC (MySQL 8.4+, MariaDB 10.11+, PostgreSQL 15+, SQL Server 2019+, H2), Redis 7.0+, MongoDB 6.0+, ZooKeeper
  34. 3.8+, and cosid-server; declared once, mixed freely.
  35. ## Version compatibility
  36. | CosId | Spring Boot | Java | Branch |
  37. |-------|-------------|------|--------|
  38. | 5.x | 4.1.2+ | 21+ | `main` |
  39. | 4.x | 4.x | 17+ | `4.x` (maintenance: bug fixes only) |
  40. | 3.x | 4.x | 17+ | `3.x` |
  41. | 2.x | 3.x | 17+ | `2.x` |
  42. | 1.x | 2.x | 8+ | `1.x` |
  43. Upgrading from 4.x: the [migration guide](https://cosid.ahoo.me/guide/migration/from-4x.html). 4.x and 5.0 never run in
  44. one namespace.
  45. ## Quick start
  46. ```kotlin
  47. dependencies {
  48. implementation(platform("me.ahoo.cosid:cosid-bom:$cosidVersion"))
  49. implementation("me.ahoo.cosid:cosid-spring-boot-starter")
  50. implementation("me.ahoo.cosid:cosid-store-jdbc") // or cosid-store-redis, -mongo, -zookeeper, -remote
  51. }
  52. ```
  53. ```yaml
  54. cosid:
  55. namespace: ${spring.application.name}
  56. stores:
  57. db:
  58. type: jdbc # the application's DataSource
  59. machine:
  60. leased:
  61. store: db # the machine slot, leased from the store
  62. generators:
  63. default:
  64. strategy: snowflake
  65. order:
  66. strategy: segment
  67. store: db
  68. codec: [ { radix: { radix: 62 } }, { prefix: "O" } ]
  69. ```
  70. ```java
  71. public OrderService(IdGenerator ids, @Qualifier("order") IdGenerator orderIds, CosIdRuntime runtime) {
  72. long id = ids.generate(); // the "default" Snowflake
  73. String orderNo = runtime.stringGenerator("order").generate();
  74. }
  75. ```
  76. [Getting Started](https://cosid.ahoo.me/guide/getting-started.html) covers Maven and plain Java too.
  77. ## Modules
  78. | Artifact | Contents |
  79. |---|---|
  80. | `cosid-core` | generators, layouts and codecs, slot leases, `CosIdRuntime`, `@CosId` field filling; depends on `slf4j-api` only |
  81. | `cosid-store-jdbc` | JDBC store: MySQL, MariaDB, PostgreSQL, SQL Server, H2, and the `JdbcDialect` SPI |
  82. | `cosid-store-redis` | Redis store (Lettuce); see its [durability precondition](./store/redis/README.md) |
  83. | `cosid-store-mongo` | MongoDB store (replica set) |
  84. | `cosid-store-zookeeper` | ZooKeeper store (Curator) |
  85. | `cosid-store-remote` | the client of cosid-server (JDK `HttpClient`) |
  86. | `cosid-store-tck` | the store contracts and an in-memory store, for tests |
  87. | `cosid-spring-boot-starter` | Spring Boot: core + `cosid-spring-boot-autoconfigure`; add the stores you use |
  88. | `cosid-jackson`, `cosid-mybatis`, `cosid-spring-data-jdbc`, `cosid-activiti`, `cosid-flowable`, `cosid-axon` | integrations, one per library |
  89. | `cosid-sharding` | sharding algorithms: `ModCycle`, `IntervalTimeline`, `CachedSharding` |
  90. | `cosid-bom` | the versions of all of the above |
  91. | cosid-server | the remote store service, a Docker image ([`server/`](./server/README.md)) |
  92. | `cosid-migration.jar` | the offline 4.x → 5.0 tool ([`migration/`](./migration/README.md)) |
  93. ## Documentation
  94. - [Why CosId](https://cosid.ahoo.me/guide/introduction.html) and [ID recipes](https://cosid.ahoo.me/guide/recipes.html).
  95. - Concepts: [layouts and codecs](https://cosid.ahoo.me/guide/concepts/layout-and-codecs.html),
  96. [the machine slot lease](https://cosid.ahoo.me/guide/concepts/slot-lease.html),
  97. [segments](https://cosid.ahoo.me/guide/concepts/segment.html), [the runtime](https://cosid.ahoo.me/guide/concepts/runtime.html).
  98. - [Choosing a backend](https://cosid.ahoo.me/guide/backends/): supported versions, measured compatibility, preconditions.
  99. - [cosid-server](https://cosid.ahoo.me/guide/server.html): API, authentication, limits, Docker.
  100. - [Configuration reference](https://cosid.ahoo.me/reference/config/basic.html): every `cosid.*` property and its default.
  101. - [Operations](https://cosid.ahoo.me/guide/operations/production.html): production checklist, metrics, health, troubleshooting.
  102. - [Migrating from 4.x](https://cosid.ahoo.me/guide/migration/from-4x.html).
  103. - The design: [`docs/architecture/`](./docs/architecture/README.md) (decisions D1–D30).
  104. The [examples](./examples/README.md) are runnable applications: `segment-jdbc`, `snowflake-redis` and `server`.
  105. ## Performance
  106. 5.0 must not be slower than 4.x in any scenario: every [benchmark](https://cosid.ahoo.me/reference/performance/benchmark.html)
  107. runs on the released 4.1.0 and on 5.0, and the comparison is a release gate. Results go to [`docs/jmh/`](./docs/jmh).
  108. The hot path of a segment id is one atomic add; a Snowflake id is a short critical section that never waits under its
  109. lock.
  110. ## Contributing
  111. Bug reports, ideas and pull requests are welcome. Read [CONTRIBUTING.md](./CONTRIBUTING.md) for the development setup, commit conventions, review and release process, and [SECURITY.md](./SECURITY.md) to report a vulnerability privately. The planned work is in the [roadmap](./docs/architecture/roadmap.md).
  112. ## Community Partners and Sponsors
  113. <a href="https://www.jetbrains.com/?from=CosId" target="_blank">
  114. <img src="./docs/jetbrains-logo.png" title="JetBrains" width=130 />
  115. </a>

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.