finds.dev← search

// the find

bwmarrin/snowflake

★ 3,339 · Go · BSD-2-Clause · updated Jul 2024

A simple to use Go (golang) package to generate or parse Twitter snowflake IDs

A Go package for generating and parsing Twitter-style snowflake IDs — 63-bit integers that encode a timestamp, node ID, and sequence number. It's a solved problem and this package solves it correctly. Useful when you need sortable, distributed-safe IDs without a coordination service.

Node bit and step bit counts are configurable, so you can trade node range for sequence density depending on your topology. Monotonic clock protection is included, which matters more than most people realize until they hit a clock skew event in production. JSON marshal/unmarshal is built in, which removes the usual friction of using snowflake IDs in HTTP APIs. The package is genuinely stable — 'completed' is accurate, not an excuse for abandonment.

Node ID assignment is entirely your problem. The package has no coordination mechanism, so if you're running more than one instance you need something external (ZooKeeper, a DB row, etcd) to hand out unique node numbers — a fact mentioned briefly but not addressed. The custom epoch/bit configuration is global state set via package-level variables, which is a bad pattern in libraries; it breaks if two packages in the same binary need different settings. No support for node IDs larger than 10 bits without recompiling the bit layout, which becomes a constraint if you're running more than 1023 nodes.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →