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
| Property | Auto-increment integer | UUID v7 |
|---|---|---|
| Size | 4 bytes (INT) / 8 bytes (BIGINT) | 16 bytes |
| Ordering | Strict total order | Chronological (ms precision) |
| Uniqueness scope | Single table/sequence | Global across all nodes |
| Coordination | Central counter required | None |
| Enumerability | Trivially enumerable | Opaque |
| Distribution | Sequential — good B-tree fill | Sequential prefix — good B-tree fill |
| Gaps | Gaps from rollbacks | Random 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:
- Strict gaplessness is required — regulated financial ledgers, legal document numbering, cheque sequences
- Storage efficiency is critical — 4-byte INT vs 16-byte UUID matters at billions of rows
- Human-readable IDs are valuable — support tickets, invoice numbers, order IDs shown to users
- Single-writer system — no distributed coordination needed, so the centralisation cost is zero
Use UUID v7 when:
- Multiple writers — distributed nodes, microservices, edge functions
- Global uniqueness — IDs must be unique across tables, services, or systems
- Security — enumerable integers leak row counts and enable IDOR attacks
- Merging data — import rows from external systems without ID conflicts
See UUID Primary Keys vs Auto-Increment for the full comparison.
Related terms
- Monotonic Counter — strict within-ms ordering for UUID v7
- Time Precision — UUID v7 millisecond timestamp
- Collision — probability of two UUIDs being identical
- Sortable ID — time-ordered identifier category
- Opaque Identifier — identifiers that hide internal structure
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.