Runs in your browser — nothing you enter leaves this pageRFC 9562 · ULID spec · Postgres 13–18 · Rails 7.1–8.1
Generate
48-bit millisecond timestamp, then 74 random bits. Sorts by creation time.

Inspect a UUID or ULID
With or without hyphens, braces or a urn:uuid: prefix; ULIDs in any case.

A UUID is 128 bits. The version (4 bits) says how the rest was made, and the variant (2 bits, 10) says the value follows RFC 9562, which replaced RFC 4122 in 2024.

How it works

Generating. Pick a type and a count from 1 to 1,000:

Both time-ordered generators are monotonic. When two IDs fall in the same millisecond, the second keeps the timestamp and increases the random part: a v7 by a random step from 1 to 2^32 (RFC 9562 advises against a step of 1 where IDs should be hard to guess), a ULID by exactly 1, as its spec defines. A clock that goes backwards keeps the last timestamp, so a batch is always sorted.

Inspecting. Paste a UUID (hyphens, braces and urn:uuid: are optional) or a ULID. The tool reports the version, the variant, the timestamp for v1, v6, v7 and ULID, and the clock sequence and node for v1 and v6. It flags the Nil and Max UUIDs and values with another variant or an undefined version, and shows the same 128 bits in the other notation. Nothing you paste or generate leaves the page.

A worked example

The RFC’s own UUIDv7 test vector is filled in for you: 017F22E2-79B0-7CC3-98C4-DC0C0C07398F. The first 12 hex digits, 017F22E279B0, are 1645557742000 milliseconds, which is 22 February 2022 at 19:22:22 UTC (2:22:22 PM in New York). The 7 that starts the third group is the version. The 9 that starts the fourth group is binary 1001; its first two bits, 10, are the variant. The tool’s tests check every field against the RFC’s table, along with the v1 and v6 vectors, which encode the same moment in 100-nanosecond steps since 15 October 1582.

UUID primary keys in Postgres and Rails

A uuid takes 16 bytes, twice a bigint. The bigger difference is where new keys go in the primary key’s B-tree index. Random v4 keys land on random leaf pages. Each insert dirties a page that may not be in memory, splits leave pages half full, and the first change to a page after a checkpoint writes the whole page to the WAL. Time-ordered keys (v7, ULID, or a sequence) all go to the right edge of the index. The same few pages stay hot, and splits mostly happen at the end.

In Rails, id: :uuid creates the column with a database default:

create_table :orders, id: :uuid do |t|
  t.references :customer, type: :uuid, foreign_key: true
  t.timestamps
end

The Rails guide says gen_random_uuid() is assumed when you pass no :default. That function produces v4. It is built into Postgres 13 and later; before 13 it came from the pgcrypto extension. Postgres 18 adds uuidv7(), which you can name as the default:

create_table :orders, id: :uuid, default: -> { "uuidv7()" } do |t|
  # ...
end

On an older Postgres, generate the key in Ruby instead. SecureRandom.uuid_v7 exists from Ruby 3.3:

class Order < ApplicationRecord
  before_create { self.id ||= SecureRandom.uuid_v7 }
end

With v4 keys, Order.first and Order.last sort by a random value. Set self.implicit_order_column = "created_at" to fix that. With v7 keys, ordering by id follows creation order to the millisecond.

The trade-off is privacy. A v7 or a ULID tells anyone who sees it when the row was created. Paste one here and you can read the time. If that matters, for example in a public URL, use v4. If you store ULIDs, put them in a uuid column (16 bytes) rather than as 26-character text, and convert at the edges.

UUID keys also help job systems: idempotent AI workers in Rails keys its idempotency gate on a record UUID that exists before the job is enqueued.

Limitations

Frequently asked questions

Should I use UUIDv7 or UUIDv4 for a primary key?

For a primary key in Postgres, v7 is usually the better choice: new rows get increasing keys, so inserts land at the right edge of the B-tree index instead of on random pages. Use v4 when the ID must not reveal when the row was created, because a v7 carries its creation time to the millisecond.

Is a ULID the same as a UUIDv7?

They have the same idea and the same 48-bit millisecond timestamp, but different bits. A ULID uses all 80 remaining bits for randomness and is written in 26 Crockford base32 characters. A UUIDv7 gives up 6 of those bits to the version and variant fields and is written as 36 hex characters with hyphens. A ULID stored in a uuid column is 128 bits like any UUID, but it is not a valid v7.

Are IDs generated in the same millisecond still in order?

Yes, within one batch or page session. When two IDs share a millisecond, the later one keeps the timestamp and increases the random bits: a v7 adds a random step (RFC 9562 §6.2 Method 2), and a ULID adds one, as the ULID spec says. A batch of 1,000 is therefore already sorted. IDs from separate machines are only ordered to the millisecond.

How random are the generated IDs?

All randomness comes from the browser's Web Crypto API: crypto.randomUUID for v4 where the browser has it, otherwise crypto.getRandomValues, which also supplies every v7 and ULID. Math.random is never used. Nothing is sent anywhere, and the page makes no network requests.

Get new articles by email

Deep dives on Rails reliability, when they're published. No spam.