Snowflake ID generator
One server gives each new post an ID. Each column is one millisecond, and its height is how many of the 4,096 sequence numbers that millisecond used.
Ready
100 posts per ms on average · 0 of 1,000 ms, slowed down so you can watch
The slider and step controls are on desktop.
What it is
This page runs one server that makes IDs on its own, without asking a central counter. Each ID packs the time in milliseconds, the server's machine ID, and a sequence number for posts made in the same millisecond, laid out the way Twitter's Snowflake does it, and you choose how busy the server is. Each sentence about Twitter's own design links to the words in its source that support it.
The main picture is an ID grid. Each column is one millisecond and each row is one sequence number, so a column's height is how many IDs that millisecond made, and a column that reaches the top line has used every number it has. A strip under the grid shows the posts left waiting for a later millisecond. Beside it, the newest ID is split into its fields, with the time, machine and sequence it holds.
The run is a simulation on a virtual clock, one millisecond per step, slowed down so you can watch, and it pauses the first time posts have to wait. Each millisecond's posts are drawn at random around the average you set, from a fixed seed, so the same setting replays the same traffic and New traffic draws another. Posts that don't fit are numbered first in the next millisecond, oldest first. Every sentence about Twitter's own design ends in a numbered link to the words in its source, listed under Sources.
How to use it
- Drag the slider to set the average posts per millisecond, or pick a preset rate.
- Run, Pause, Step one millisecond at a time, Replay, or change the speed.
- Take the tour for three runs: plenty of room, a burst that waits, and a queue that never drains.
- On a phone the default run starts on its own unless reduce-motion is on, with Play, Pause and the tour.
More experiments
- Groove — Canvas, Web Audio, Music
- Marble Ink — canvas, generative, computational-geometry
- Indus script explorer — Indus script, Archaeology, Writing systems
Sources
Each sentence about Twitter's Snowflake ends in a number. It links here, to the words in Twitter's 2010 Snowflake repository that support it. Every other number on the page is arithmetic on the bit layout or comes from the simulated run, whose clock starts at the real time the run began.
[1]Twitter built Snowflake to make unique IDs at high scale.
“Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees.”
Snowflake README (Twitter, 2010) · primary source[2]Snowflake's servers make IDs without asking each other.
“machines generating ids should not have to coordinate with each other.”
Snowflake README (Twitter, 2010) · primary source[3]Snowflake spends 41 bits on milliseconds, good for 69 years.
“time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years)”
Snowflake README (Twitter, 2010) · primary source[4]Snowflake's epoch is 1288834974657 ms, which is 2010-11-04.
“val twepoch = 1288834974657L”
IdWorker.scala (Twitter's Snowflake source, 2010) · primary source[5]Snowflake's 12-bit sequence allows 4,096 IDs per server in each millisecond.
“sequence number - 12 bits - rolls over every 4096 per machine (with protection to avoid rollover in the same ms)”
Snowflake README (Twitter, 2010) · primary source