Snowflake ID is a 64-bit time-ordered identifier format created by Twitter in 2010 for generating unique IDs at scale without a centralized sequence generator. It has since been adopted and adapted by Discord, Instagram (with a different epoch), and many other services.
Snowflake ID bit layout
63 0
┌────────────────────────────────────────────────────────────────┐
│ 41-bit timestamp (ms since custom epoch) │ 10-bit │ 12-bit │
│ │machine │sequence │
└────────────────────────────────────────────────────────────────┘
| Field | Bits | Description |
|---|---|---|
| Sign bit | 1 | Always 0 (positive integer) |
| Timestamp | 41 | Milliseconds since custom epoch (e.g. 2010-11-04) |
| Machine ID | 10 | Datacenter (5 bits) + worker (5 bits) |
| Sequence | 12 | Up to 4096 IDs per millisecond per machine |
UUID v7 bit layout comparison
127 0
┌────────────────────────────────────────────────────────────────┐
│ 48-bit Unix ms timestamp │ ver │ rand_a │ var │ rand_b │
│ │ 4b │ 12 bits │ 2b │ 62 bits │
└────────────────────────────────────────────────────────────────┘
| Field | Bits | Description |
|---|---|---|
| Timestamp | 48 | Unix milliseconds since 1970-01-01 |
| Version | 4 | Always 0b0111 (version 7) |
| Random A | 12 | Random bits |
| Variant | 2 | Always 0b10 |
| Random B | 62 | Random bits |
| Total random | 74 | No machine ID required |
See UUID Bit Fields for the full v7 layout.
Key differences
| Property | Snowflake ID | UUID v7 |
|---|---|---|
| Size | 64 bits (BIGINT) | 128 bits (UUID) |
| Coordination | Machine ID registry required | None — 74 random bits |
| Standard | Proprietary (Twitter) | RFC 9562 |
| Epoch | Custom (2010 or similar) | Unix epoch (1970-01-01) |
| Sequence | 4096/ms per machine | Probabilistic (74 random bits) |
| Collision risk | 0 if machine IDs unique | ~2.6×10⁻¹¹ per trillion IDs |
| DB column type | BIGINT | UUID (16 bytes) |
| Human-readable | As integer or binary | Standard UUID string |
When to use Snowflake IDs vs UUID v7
Prefer Snowflake ID when:
- Your schema requires BIGINT primary keys for legacy system compatibility
- You have a controlled deployment where machine ID assignment is feasible
- You need exactly 4096 guaranteed-unique IDs per millisecond per node
Prefer UUID v7 when:
- Generating IDs in serverless functions, browsers, or edge runtimes
- You want a database-native UUID column type
- You need a standard format with broad library and tooling support
- Avoiding central coordination is a requirement
Further reading
- ULID — Sortable alternative to UUID
- UUID v4 vs UUID v7
- UUID Bit Fields — Version and Variant
- What is a UUID
- Sortable ID
Frequently asked questions
What is a Snowflake ID?
A Snowflake ID is a 64-bit integer composed of a 41-bit millisecond timestamp (from a custom epoch), a 10-bit machine/datacenter ID, and a 12-bit sequence number. It was created by Twitter and later adopted by Discord, Instagram, and other high-traffic services. Snowflake IDs sort chronologically as integers and fit in a database BIGINT column. See ULID for another Snowflake alternative.
What are the limitations of Snowflake IDs compared to UUID v7?
Snowflake IDs require each generator instance to have a unique machine ID — typically assigned from a central registry or ZooKeeper. Without coordination, two generators with the same machine ID can produce collisions within the same millisecond sequence. UUID v7 avoids this with 74 random bits: no machine ID registry, no coordination, and safe to generate in serverless functions, Lambda, or Cloudflare Workers. See What is a UUID.
Should I use Snowflake IDs or UUID v7 for new projects?
For new projects, UUID v7 is generally preferred: it is an RFC standard (RFC 9562), requires no coordination, uses a standard format supported by most databases and ORMs, and fits in a UUID column (16 bytes). Snowflake IDs are better if you need a BIGINT primary key for SQL Server or MySQL compatibility or require a 64-bit ID for legacy interop. See UUID v4 vs v7.