How the ID generation algorithm works
v2katsubushi uses a Snowflake-like algorithm to generate 64-bit unsigned integer IDs.
Default Format (64-bit)
- timestamp (42 bits): Milliseconds since katsubushi epoch (2015-01-01 00:00:00 UTC). Lasts ~139 years.
- worker ID (10 bits): Supports up to 1024 workers.
- sequence (12 bits): Up to 4096 IDs per millisecond per worker.
JS-safe Format (53-bit)
Use the -js-safe-id flag to generate IDs that fit within JavaScript's Number.MAX_SAFE_INTEGER (2^53 - 1). This prevents precision loss in JS environments.
- timestamp (39 bits): 10ms units since epoch. Lasts ~174 years.
- worker ID (6 bits): Up to 64 workers.
- sequence (8 bits): Up to 256 IDs per 10ms per worker.
Warning: Do not mix default and JS-safe formats in the same service. If using -js-safe-id with -redis, use a different namespace (?ns=) to avoid worker ID collisions.