KSUID Generator
Press c to copy or r for a new one
Generate in bulk
What is a KSUID?
A KSUID is 20 bytes printed as 27 characters of base62. The first four bytes count seconds from 13 May 2014, an epoch Segment picked so that a 32-bit counter has room left until 2150. The remaining 16 bytes are random.
The name is short for K-Sortable Unique Identifier, and Segment published the original Go implementation. Base62 covers digits and both cases of the alphabet, so a KSUID never needs escaping in a URL and is always exactly 27 characters wide.
Why use a KSUID?
The timestamp leads, so sorting KSUIDs as text puts them in creation order. An index keyed on them stays close to append-only, which is the whole reason anyone picks a time-ordered ID over a random one.
The 16 random bytes are worth calling out. That is 128 bits of entropy against a ULID's 80, so a KSUID has far more room before two IDs minted in the same tick could ever land on each other.
The cost of second resolution
A KSUID timestamp counts whole seconds. Every KSUID made inside one second therefore sorts by its random payload, which is to say arbitrarily. ULID and UUID v7 both count milliseconds and order a thousand times finer.
Whether that costs you anything depends on how fast you write. At a handful of rows a second nobody will ever notice the difference. At thousands, the finer clock keeps a B-tree tidier.
What it gives away
The creation second travels in the open, readable by anyone holding the ID. A KSUID is fine as a primary key and a poor choice for anything that has to stay secret, such as an invite link or a password reset token.
Paste one into the decoder and the timestamp comes straight back out.
Generate one in code
TypeScript
import KSUID from "ksuid";
KSUID.randomSync().string;Python
from ksuid import Ksuid # pip install svix-ksuid
str(Ksuid())Go
import "github.com/segmentio/ksuid"
ksuid.New().String()Rust
// cargo add svix-ksuid
use svix_ksuid::*;
Ksuid::now(None).to_string();