How it works
A database sequence or ticket service gives straightforward unique numeric IDs. A ticket service is a small database whose only job is handing out the next number; Flickr described running two MySQL ticket servers, one issuing odd numbers and the other even. Every generator then depends on a central allocator unless it leases ranges. With a lease, a worker takes a block of, say, 10,000 numbers and spends it locally. At 500 IDs per second it calls the allocator every 20 seconds rather than 500 times a second, and it can ride out an allocator outage for up to that long. A crash discards the unused remainder, leaving gaps. Fixed offsets like odd and even become awkward as machines join or leave.
A UUID is a 128-bit identifier. UUIDv4 is random apart from 6 fixed bits, so machines generate it independently with negligible collision risk, but random values land on scattered B-tree pages and slow inserts into large indexes. UUIDv7, standardized in RFC 9562, starts with a 48-bit Unix millisecond timestamp followed mostly by random bits. It sorts roughly by creation time and needs no worker coordination, and Postgres 18 can generate it natively. If 128-bit keys fit your columns and clients, it is often the easiest choice.
Neither version meets this exercise’s 64-bit numeric contract. If compact, approximately time-ordered integers are required, a Snowflake-style layout is a useful candidate, at the cost of assigning worker IDs and watching clocks. Choose the simplest design that meets the actual contract; decentralization is not a virtue by itself.
A small internal tool needs only 500 IDs per second and already has one reliable database. Must it deploy a Snowflake service?
No. A database sequence may meet the stated scale and availability target more simply. Revisit range leasing or distributed generation only when measured needs justify it.
Use this as a guide for self review; written answers are not graded.Keep in mind
- A central allocator is simple until it becomes a latency or availability dependency.
- UUIDv7 adds time order without coordination, but at 128 bits it answers a different contract from a 64-bit numeric ID.