Generate compact IDs for fixtures and testing

Seed data, test fixtures, and shareable links all need IDs that are short, URL-safe, and unlikely to collide.

Tools used in this guide

The job

UUIDs work everywhere but are long and ugly in URLs. NanoID packs the same randomness into 21 URL-safe characters; ULID trades some compactness for sortability — it starts with a timestamp so IDs sort in creation order.

Generate a batch

Pick NanoID or ULID, set the count, and generate. For NanoID you can also set the length and restrict the alphabet — digits only, lowercase, or no lookalikes.

  • 21 characters of the default alphabet gives ~126 bits — collision-safe for most uses.
  • ULIDs are 26 characters, monotonic by millisecond, and embed no other data.

Worked example

Seeding 50 test users: generate 50 NanoIDs at the default size, paste them into the fixture file as id fields. For audit-log rows that must sort by creation time without an index, use ULIDs instead.

Limits and randomness

IDs are drawn from crypto.getRandomValues with rejection sampling, so every alphabet character is equally likely — the same quality as UUID v4. Up to 100 per run; NanoID length up to 512 characters.

  • NanoID is case-sensitive URL-safe; don't feed it to systems that lowercase identifiers.
  • For guaranteed database uniqueness you still need a unique constraint — generated IDs are random, not coordinated.