AlgoViz

Unique ID generator

medium 28 min

Give every record its own number, from many servers at once.

When it comes up

The moments this idea belongs in a design interview, and the moments it does not.

Signals

When to bring it up

You hearSayBecause
Many servers create recordsTime-ordered IDs made in each serverNo central counter
Short public codeLeased range, scrambled, in base 62Short and unique
Newest firstSnowflake or UUIDv7 as the cursorThe ID is already in order
Private linkRandom token with expiryIDs can be guessed
Chat orderSequence per conversationClocks do not give exact order

Twenty services in three regions create orders. How do they get IDs?

BreaksA counter in each service
How
Every service counts from 1.
Limit
Duplicates on the first day.
Choose when
Never with more than one writer.
WorksOne ID service with a sequence
How
Each order asks it for a number.
Limit
Every order depends on it, and two regions wait for a far one.
Choose when
One region with modest volume, and blocks of numbers instead of one by one.
StrongIDs made in each instance
How
UUIDv7, or Snowflake with leased machine numbers and clock guards. Primary key as the last check.
Limit
Order across machines is only approximate.
Choose when
Several writers or regions.