A Rust web service implementing Twitter's Snowflake ID generation algorithm. Generates unique, time-sorted 64-bit identifiers suitable for distributed systems.
You can install the chart directly from the GitHub release:
helm install my-id-generator https://github.com/Edthing/id-generator/releases/download/id-generator-0.1.0/id-generator-0.1.0.tgz --set autoscaling.keda.enabled=true- Single ID generation endpoint
- Bulk ID generation (up to 4,096,000 IDs per request)
- Health check endpoint for container orchestration
- Handles clock drift and leap seconds with timeout protection
- Thread-safe sequence management
- Configurable worker threads
- Comprehensive input validation
Returns a single unique ID.
{"id": "123456789012345678"}Returns multiple unique IDs (count must be 1 to 4,096,000).
{"ids": ["123456789012345678", "123456789012345679", ...]}Health check endpoint for container orchestration (Kubernetes, Docker, etc.).
{"status": "healthy", "worker_id": 1}Prometheus metrics endpoint.
# HELP id_generator_ids_generated_total Total IDs generated
# TYPE id_generator_ids_generated_total counter
id_generator_ids_generated_total 123
# HELP id_generator_sequence_exhausted_total Times sequence was exhausted within a millisecond
# TYPE id_generator_sequence_exhausted_total counter
id_generator_sequence_exhausted_total 0
# HELP id_generator_worker_id Worker ID of this instance
# TYPE id_generator_worker_id gauge
id_generator_worker_id 1
All errors return JSON with a consistent format:
{"error": "Error message description"}| Environment Variable | Description | Required | Default |
|---|---|---|---|
WORKER_ID |
Unique worker identifier (0-1023) | Yes | - |
WORKERS |
Number of HTTP worker threads | No | 1 |
The included Helm chart supports both standard HPA (CPU/Memory) and KEDA-based autoscaling (based on sequence exhaustion).
To enable KEDA autoscaling:
- Ensure KEDA is installed in your cluster.
- Set
autoscaling.keda.enabled=trueinvalues.yaml. - Configure
autoscaling.keda.prometheusServerAddressto point to your Prometheus instance.
The scaler monitors the rate(id_generator_sequence_exhausted_total[1m]) metric. If the sequence limit (4096 IDs/ms) is hit frequently, KEDA will scale up the number of pods.
docker run -d -p 8080:8080 -e WORKER_ID=1 ghcr.io/Edthing/id-generatorcargo build --release
WORKER_ID=1 ./target/release/id-generatorThe server listens on 0.0.0.0:8080.
IDs are 64-bit integers with the following structure:
| Bits | Field | Description |
|---|---|---|
| 41 | Timestamp | Milliseconds since custom epoch |
| 10 | Worker ID | Identifies the generating node |
| 12 | Sequence | Per-millisecond counter (0-4095) |
GNU Affero General Public License v3.0