yitter/IdGenerator logo

yitter/IdGenerator

Free

💎多语言实现,高性能生成唯一数字ID。 💎优化的雪花算法(SnowFlake)——雪花漂移算法,在缩短ID长度的同时,具备极高瞬时并发处理能力(50W/0.1s)。 💎原生支持 C#/Java/Go/Rust/C/JavaScript/TypeScript/Python/Pascal 多语言,提供其它适用于其它语言的多线程安全调用动态库(FFI)。💎支持容器环境自动扩容(自动注册 WorkerId ),单机或分布式唯一IdGenerator。💎顶尖优化,超强效能。

FreeFree tier
Type
Open Source

About yitter/IdGenerator

IdGenerator is an optimized implementation of the Snowflake algorithm (Snowflake Drift) that generates shorter unique numeric IDs at higher speeds than traditional Snowflake. It natively supports multiple programming languages including C#, Java, Go, Rust, C, JavaScript, TypeScript, Python, Pascal, PHP, SQL, and Delphi, with additional languages supported via FFI. The algorithm achieves high throughput (500k IDs per 0.1 seconds with default configuration, up to 3000W IDs per second with tuning), handles time rollback gracefully, allows manual insertion of historical IDs, and supports container environment auto-scaling with automatic WorkerId registration (optional Redis dependency in K8s). It is designed for distributed systems, database primary keys, and scenarios requiring time-ordered unique IDs, with a lifespan of over 71,000 years under default settings.

Key Features

Optimized Snowflake algorithm (Snowflake Drift) for shorter IDs and higher performance
Native support for C#, Java, Go, Rust, C, JavaScript, TypeScript, Python, Pascal, PHP, SQL, Delphi, and more via FFI
Supports container environment auto-scaling with automatic WorkerId registration (optional Redis)
Handles time rollback gracefully without ID collisions
Supports manual insertion of IDs in historical time (up to 5000 IDs per second)
High throughput: 500k IDs per 0.1s (default config), up to 3000W IDs per second
No external database or cache required for basic operation
Generates IDs within JavaScript Number.MAX_SAFE_INTEGER for 70 years (default config)
Compatible with all classic Snowflake algorithms for seamless upgrade
Configurable WorkerId bit length and sequence bit length for performance tuning

Pros & Cons

Pros
  • Very high performance: up to 3000W IDs per second with tuning
  • Generates shorter IDs than traditional Snowflake, saving storage
  • Handles time rollback automatically without collision
  • Multi-language support enables integration across diverse tech stacks
  • No external dependencies for basic use (database, cache, etc.)
  • Long lifespan: over 71,000 years before ID exhaustion
  • Compatible with existing Snowflake systems for easy migration
Cons
  • WorkerId must be globally unique; distribution management required outside K8s environments
  • Performance tuning requires understanding of parameters (WorkerIdBitLength, SeqBitLength)
  • Depends on system clock accuracy; extreme drifts may cause ID sequence issues (though algorithm handles limited rollbacks)
  • Optional Redis dependency for automatic WorkerId registration in container environments

Best For

Database primary keys in distributed systemsSharding and table partitioning with time-ordered IDsMicroservices and containerized applications requiring unique IDsHigh-concurrency systems needing fast ID generationScenarios where short IDs are beneficial (e.g., frontend JavaScript compatibility)Systems requiring time rollback tolerance without external dependencies

FAQ

How many IDs can IdGenerator generate per second?
With default configuration, IdGenerator can generate 50W IDs per 0.1 seconds (5 million IDs/second). By adjusting SeqBitLength to 12, it can achieve up to 3000W IDs per second.
Does IdGenerator handle time rollback?
Yes, it uses reserved sequence numbers to generate IDs during time rollback without collisions. The algorithm can automatically adapt to rollbacks within a configurable range.
Is IdGenerator compatible with traditional Snowflake IDs?
Yes, it is fully compatible with all classic Snowflake algorithms (segment mode or standard mode). You can upgrade or switch between them seamlessly.
What programming languages are supported?
Native support is provided for C#, Java, Go, Rust, C, JavaScript, TypeScript, Python, Pascal, PHP, SQL, Delphi, and more. Additional languages can use the multi-threaded safe FFI dynamic library.
Does IdGenerator require a database or external cache?
No, it does not require any external database or cache for basic operation. The only exception is the optional use of Redis for automatic WorkerId registration in K8s container environments.