Effect Snowflake ID Generator
Coordination-free 64-bit ids that refuse to trust the clock: 41 bits of milliseconds since a custom epoch, 10 bits of machine id, 12 bits of sequence, minted locally at up to 4096 ids per millisecond per machine and still roughly time-sorted. The (lastTimestamp, sequence) pair lives in one Ref and every mint is one atomic Ref.modify, so concurrent fibers cannot interleave into a duplicate, an exhausted sequence parks until the next tick, a small clock rollback parks until the clock re-passes the high-water mark, and a rollback beyond tolerance is a typed ClockMovedBackward failure instead of a silent collision. Solves the central sequence bottleneck and duplicate ids on clock rollback. Pinned to effect 4.0.0-beta.98.
npx shadcn@latest add https://ui.aryank.space/r/effect-snowflake-id-generator.jsonInstalls from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.
NTP steps the wall clock back 60 seconds and the generator keeps minting from it. The odometer rolls BACKWARD: it re-issues timestamp bits it already used, and somewhere a new order id collides with one from a minute ago. Two rows, one primary key.