CUID v1 anatomy and a safe migration path

CUID v1 is deprecated, but existing identifiers still need to be read and preserved. This guide shows what its fields reveal, what parsing cannot establish, and how to introduce a successor without rewriting history.

Review notes,

The sample timestamp decode and format boundaries are covered by repository tests against cuid 3.0.0.

The field map follows the legacy implementation's documented layout. The example is decoded independently from its eight-character base36 timestamp segment, while all claims about origin remain explicitly unverified.

Anatomy of one 25-character value

cjld2cjxh0000qzrmn831i7rn
FieldCharactersSampleEvidence statusWhat can be said
Prefix1cParsedLiteral marker used by the CUID v1 format.
Timestamp2–9jld2cjxhParsedEight base36 characters interpreted as Unix-epoch milliseconds.
Counter10–130000Position inferredThe value can be read, but the generator's counter state cannot be verified later.
Fingerprint14–17qzrmPosition inferredThe original host and process cannot be recovered from this field.
Random18–25n831i7rnPosition inferredThe characters are visible; their source and generation event are not provable.

The legacy documentation warns that its groupings are not an API contract. Use a parser for diagnostics and migration work, not business logic that depends on undocumented field boundaries.

Worked timestamp decode

  1. 1. Validate the outer format: the site accepts exactly c followed by 24 lowercase base36 characters.
  2. 2. Select characters 2–9: jld2cjxh.
  3. 3. Decode base36: parseInt("jld2cjxh", 36) = 1535421552101.
  4. 4. Interpret milliseconds: 2018-08-28T01:59:12.101Z.
Limit: a plausible timestamp is not proof that cuid created the string at that moment. Anyone can construct text with the same visible shape, and a 25-character CUID2-format value can overlap the broad regular expression.
Inspect a value in the anatomy tool

Migration checklist

1

Inventory contracts

Find database columns, foreign keys, URLs, caches, queues, analytics exports, fixtures, and third-party integrations that assume a 25-character string or a leading c.

2

Choose the successor

Use the identifier decision guide. Record the generator, exact version, output length, storage type, and whether clients may allocate IDs.

3

Allow both formats at boundaries

During transition, parse legacy and new IDs as opaque alternatives. Never decide authorization or tenancy from the format.

4

Keep old primary keys stable

Do not rewrite historical identifiers merely for visual consistency. Add a new public key or mapping column only when a concrete contract requires it.

5

Switch writes before cleanup

Deploy readers that accept both formats, then move new writes to the successor, then observe logs and integrations before removing the legacy generator.

6

Enforce and monitor

Use a primary-key or unique constraint for the new value, handle duplicate insert errors, and alert on validation or mapping failures.

A two-format transition shape

Illustrative PostgreSQL schema
sql
ALTER TABLE project
  ADD COLUMN public_id varchar(24);

CREATE UNIQUE INDEX project_public_id_unique
  ON project (public_id)
  WHERE public_id IS NOT NULL;

-- 1. Deploy readers that accept the old primary key or public_id.
-- 2. Generate public_id for new writes.
-- 3. Backfill only if external contracts require every old row to have one.

This is a migration pattern, not a drop-in script. Foreign keys, nullability, online index creation, backfill rate, and rollback behavior depend on the database and workload.

What not to do

  • Do not generate a “historical CUID” by replacing the timestamp field and treat it as equivalent to a library-generated value.
  • Do not sort business events by a parsed CUID timestamp when the authoritative event time is stored separately.
  • Do not accept a format match as proof of provenance, uniqueness, authenticity, or access rights.
  • Do not replace every legacy key in place unless all references and external contracts can be migrated atomically.

The site's timestamp-field constructor is explicitly diagnostic: it demonstrates the field layout but does not recreate the original generator state or uniqueness properties.