Definition

A sequential ID is an identifier assigned in strict ascending numerical order — typically an auto-increment integer managed by a database engine. Each INSERT receives the next integer in the sequence: 1, 2, 3, …

The defining property is strict total order with no gaps under normal operation — every identifier is exactly one greater than the previous one.

Sequential ID vs UUID v7

PropertyAuto-increment integerUUID v7
Size4 bytes (INT) / 8 bytes (BIGINT)16 bytes
OrderingStrict total orderChronological (ms precision)
Uniqueness scopeSingle table/sequenceGlobal across all nodes
CoordinationCentral counter requiredNone
EnumerabilityTrivially enumerableOpaque
DistributionSequential — good B-tree fillSequential prefix — good B-tree fill
GapsGaps from rollbacksRandom bits vary within ms

UUID v7 approximates sequential ordering without a central counter — its 48-bit Unix millisecond timestamp ensures that IDs generated later sort after IDs generated earlier (assuming monotonic clock). See Monotonic Counter for within-millisecond strict ordering.

The coordination problem with sequential IDs

-- Centralised sequence — requires serialised access
CREATE SEQUENCE order_id_seq;
SELECT nextval('order_id_seq');  -- one at a time

In a single-writer database, this is trivial. In a distributed system with multiple application nodes or shards, the central sequence becomes a bottleneck — or must be replaced with range-allocation schemes (e.g., assign blocks of 1000 IDs to each node). UUID v7 eliminates this by embedding the source of ordering (the clock) into the ID itself. See UUID v7 in Distributed Systems.

UUID v7 as an approximate sequential ID

import { v7 as uuidv7 } from 'uuid';

// Three IDs generated 1ms apart — sort in creation order
const id1 = uuidv7(); // 018fbe3a-4c5d-7...
await sleep(1);
const id2 = uuidv7(); // 018fbe3a-4c5e-7...  (timestamp incremented)
await sleep(1);
const id3 = uuidv7(); // 018fbe3a-4c5f-7...

[id1, id2, id3].sort() // → [id1, id2, id3] — chronological order preserved

Two UUIDs generated within the same millisecond have identical timestamp prefixes. The monotonic counter (RFC 9562 §6.2 Method 1) makes them strictly ordered within that millisecond on a single node — but order is not guaranteed across two concurrent nodes in the same millisecond. See Time Precision.

When to keep sequential integers

Use auto-increment integers when:

Use UUID v7 when:

See UUID Primary Keys vs Auto-Increment for the full comparison.

External references

Frequently asked questions

What is the difference between a sequential ID and UUID v7?

A sequential ID (auto-increment integer) is assigned by a single authority in strict order — 1, 2, 3 — with no gaps under normal operation. UUID v7 is time-ordered to millisecond precision: two UUIDs generated in the same millisecond have identical timestamp prefixes and are distinguished by random bits. UUID v7 does not guarantee strict sequential order across nodes or across milliseconds — it guarantees chronological ordering. The practical difference is that UUID v7 avoids coordination overhead (no central counter) while still enabling ORDER BY id to return rows in approximate creation order. See UUID v4 vs v7 and UUID vs Auto-Increment.

Can UUID v7 replace auto-increment integers as a primary key?

Yes, for most applications. UUID v7 provides time-ordered uniqueness, works across distributed nodes without coordination, and avoids exposing record counts. The trade-offs: UUID v7 uses 16 bytes (vs 4–8 for integers), and ordering is approximate (millisecond precision) rather than exact. For systems that require strictly gapless sequences (financial ledgers, regulated audit trails), integer sequences with gap detection remain the right tool. See UUID Primary Keys vs Auto-Increment.