Snowflake ID Generator
Twitter Snowflake-style unique identifier
Generating...
About
Snowflake ID is a 64-bit unique identifier format used by Twitter. It consists of a 41-bit timestamp (milliseconds since custom epoch), 5-bit datacenter ID, 5-bit worker ID, and 12-bit sequence number. Snowflake IDs are time-ordered and can generate up to 4096 IDs per millisecond per worker. The format allows for distributed ID generation across multiple datacenters and workers without coordination, making it ideal for large-scale distributed systems.
Use Cases
- •Distributed system ID generation
- •Twitter-style social media platforms
- •High-throughput ID generation
- •Database primary keys with time ordering
- •Systems requiring no coordination between generators
- •Large-scale applications with multiple workers
How to Generate
Library
Custom implementation or snowflake-id libraries
NPM Package
npm install snowflake-id or similarCode Example
// Custom implementation
const timestamp = BigInt(Date.now() - customEpoch);
const datacenterId = BigInt(1);
const workerId = BigInt(1);
const sequence = BigInt(/* sequence counter */);
const id = (timestamp << 22n) | (datacenterId << 17n) | (workerId << 12n) | sequence;Note: Production Snowflake implementations require proper sequence management and worker/datacenter ID coordination.