❄️ SnowID Rust
A Rust implementation of a Snowflake-like ID generator with 42-bit timestamp.
Generate 64-bit unique identifiers that are:
- ⚡️ Fast (~244ns per ID)
- 📈 Time-sorted
- 🔄 Monotonic
- 🔒 Thread-safe
- 🌐 Distributed-ready
- 🎯 Zero dependencies
🧮 ID Structure
Example ID: 151819733950271234
Default configuration:
|------------------------------------------|------------|------------|
| TIMESTAMP (42 bits) | NODE (10) | SEQ (12) |
|------------------------------------------|------------|------------|
- Timestamp: 42 bits = 139 years from 2024-01-01 (1704067200000)
- Node ID: 10 bits = 1,024 nodes (valid range: 6-16 bits)
- Sequence: 12 bits = 4,096 IDs/ms/node
🎯 Quick Start
[]
= "0.1.2"
use SnowID;
🔧 Configuration
use ;
ℹ️ Available Methods
use SnowID;
📊 Performance & Comparisons
Social Media Platform Configurations
| Platform | Timestamp | Node Bits | Sequence Bits | Max Nodes | IDs/ms/node | Time/ID |
|---|---|---|---|---|---|---|
| 41 | 10 | 12 | 1,024 | 4,096 | ~242ns | |
| 41 | 13 | 10 | 8,192 | 1,024 | ~1.94µs | |
| Discord | 42 | 10 | 12 | 1,024 | 4,096 | ~245ns |
Node vs Sequence Bits Trade-off
| Node Bits | Max Nodes | IDs/ms/node | Time/ID |
|---|---|---|---|
| 6 | 64 | 65,536 | ~20ns |
| 8 | 256 | 16,384 | ~60ns |
| 10 | 1,024 | 4,096 | ~243ns |
| 12 | 4,096 | 1,024 | ~968ns |
| 14 | 16,384 | 256 | ~3.86µs |
| 16 | 65,536 | 64 | ~15.4µs |
Choose configuration based on your needs:
- More nodes → Increase node bits (max 16 bits = 65,536 nodes)
- More IDs per node → Increase sequence bits (min 6 node bits = 64 nodes)
- Total bits (node + sequence) is fixed at 22 bits
🚀 Examples
Check out examples for:
- Basic usage
- Custom configuration
- Distributed generation
- Performance benchmarks
📜 License
MIT - See LICENSE for details