Guide

What a TNID is

A TNID (Typed Named ID) is a 128-bit ID that carries a short name saying what it identifies. It closes three gaps in UUIDs:

A UUIDA TNID
A UUID doesn't say what it identifies.A TNID carries its name, such as user, in its own bits. Any code can reject the wrong name at runtime.
Every UUID has the same type, so a type system has nothing to check.In typed languages, the name can also be part of the TNID's static type, so passing the wrong kind of TNID fails to compile. See Type safety.
A UUID's hex can be written in upper or lower case, so comparing or sorting UUIDs as strings can give wrong results. JavaScript, JSON and URLs carry UUIDs as strings.Each TNID has exactly one string form. Sorting the strings as text sorts the TNIDs by value. The time-sortable kind, TNIDv0, sorts by creation time within a name.
user.Br2flcNDfF6LYICnT

user is the name. The 17 characters after the dot hold the rest of the 128 bits.

Backwards compatible with UUIDs

Every TNID is a valid UUIDv8, the UUID version for custom layouts (Bit layout). Same value, UUID form:

d6157337-0ebc-8686-83ab-4075a34cdcde

Store it in UUID columns, pass it to anything that takes UUIDs, convert back losslessly: Storing and showing TNIDs.

What else you get

  • The name survives storage. Read back from a uuid column, the TNID is still a user. TypeIDs and prefixed UUID strings lose their prefix there.
  • Mix-ups fail loudly. Parsing checks the name, so a post TNID sent as a user TNID is rejected, not silently matching nothing.
  • Readable in logs, URLs, support tickets and database dumps.
  • URL-safe: letters, digits, -, _ and . only.
  • Shorter: 19 to 22 characters, against 36 for the UUID form.

Trade-offs

Trade-offDetail
Collisions are more likely than with UUIDv4.The odds are still negligible: a billion random TNIDv1s under one name have about a 1 in 2.5 trillion chance of any collision.
Names are permanent.The name is part of every TNID, so renaming a type changes all of its TNIDs. See Names.
TNID strings are case-sensitive by design.One spelling per TNID lets the strings sort as plain text. The cost: case-insensitive text columns can't tell them apart. Store the UUID form, or use a binary collation.
TNID is still a draft.The spec is at version 0 and the libraries are pre-1.0, so details can still change.

These rarely rule TNIDs out: When to use another ID format.