Skip to content

Commit 85203e9

Browse files
committed
Cleanup repository, update README
1 parent 43ce8b7 commit 85203e9

2 files changed

Lines changed: 64 additions & 10 deletions

File tree

README.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
11
# unique-id-generator
2-
Implementation of the twitter snowflake id generation system.
2+
3+
A Rust web service implementing Twitter's Snowflake ID generation algorithm. Generates unique, time-sorted 64-bit identifiers suitable for distributed systems.
4+
5+
## Features
6+
7+
- Single ID generation endpoint
8+
- Bulk ID generation (up to 4,096,000 IDs per request)
9+
- Handles clock drift and leap seconds
10+
- Thread-safe sequence management
11+
12+
## API Endpoints
13+
14+
### GET /id
15+
16+
Returns a single unique ID.
17+
18+
```json
19+
{"id": "123456789012345678"}
20+
```
21+
22+
### GET /ids/{count}
23+
24+
Returns multiple unique IDs.
25+
26+
```json
27+
{"ids": ["123456789012345678", "123456789012345679", ...]}
28+
```
29+
30+
## Configuration
31+
32+
| Environment Variable | Description | Required |
33+
|---------------------|-------------|----------|
34+
| `WORKER_ID` | Unique worker identifier (0-1023) | Yes |
35+
36+
## Running
37+
38+
### Docker
39+
40+
```bash
41+
docker run -d -p 8080:8080 -e WORKER_ID=1 ghcr.io/Edthing/id-generator
42+
```
43+
44+
### From Source
45+
46+
```bash
47+
cargo build --release
48+
WORKER_ID=1 ./target/release/unique-id-generator
49+
```
50+
51+
The server listens on `0.0.0.0:8080`.
52+
53+
## ID Format
54+
55+
IDs are 64-bit integers with the following structure:
56+
57+
| Bits | Field | Description |
58+
|------|-------|-------------|
59+
| 41 | Timestamp | Milliseconds since custom epoch |
60+
| 10 | Worker ID | Identifies the generating node |
61+
| 12 | Sequence | Per-millisecond counter (0-4095) |
62+
63+
## License
64+
65+
AGPL-3.0

docker-compose.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)