Switch branches/tags
Nothing to show
Clone or download



Snowflake is a go implementation of Twitter's Snowflake service. Like its namespace, Snowflake is also a network service for generating unique ID numbers at high scale with some simple guarantees.



Snowflake generates unique int64 ids that (unlike uuids) are loosely time sorted. Each id consists of:

Bits Field Notes
41 Timestamp in MS ~70yrs
10 Server ID Unique Server ID
13 Sequence ID sequence to disambiguate requests in the same ms

Server Usage

The simplest way to run snowflake is via docker:

docker run -p 80:80 -it --rm savaki/snowflake:1.3

To retrieve the a single id:

curl http://your-host-name?n=4

To retrieve the N ids:

curl http://your-host-name?n=8

Client Usage

Snowflake implements two clients, a low level client, and a high level buffered client. In most cases, you'll want to use the buffered client. The buffered client maintains and replenishes an internal queue of ids so there should always be one available when you need it.

package main

import (


func main() {
	client, _ := snowflake.NewClient(snowflake.WithHosts("your-host"))
	buffered := snowflake.NewBufferedClient(client)
	fmt.Println("id:", buffered.Id())