How it works
This exercise assumes numeric IDs that fit in a signed 64-bit field, are roughly ordered by creation time, and can be generated by many machines above 25,000 IDs per second. Ask whether a strict global order is actually required, whether gaps are allowed, how long IDs must remain unique, and whether users can see them. Those choices change the design more than the requested throughput alone.
Each promise has a price. Take a shop creating 12,000 orders per second at peak (an example figure). If “ordered” means two IDs created a few milliseconds apart may sort either way, each machine can build IDs from its own clock with no network call. If it means a later ID always sorts higher, generators must coordinate, typically through one shared sequencer, which adds a round trip and a component that can fail. If finance wants invoice numbers with no gaps, the number has to be assigned inside the committing transaction, which serializes those writes. Drop any promise nobody needs: when nothing sorts by ID, ordering costs something and buys nothing.
An ID is an identity, not a timestamp or a permission check. A time-shaped value may reveal creation time and machine information, so do not treat it as secret. Databases, APIs, and JavaScript clients must represent the full integer exactly. JavaScript Number loses integer precision above 2^53−1, about 9 quadrillion, so use a string or BigInt at that boundary.
A product asks for “sortable IDs” but never defines what happens when two regions create records at once. What do you clarify?
Ask whether approximate time order is enough or a strict total order is required. A decentralized time-based generator can provide the former, while strict global order needs coordination.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Write down the exact uniqueness and ordering promise.
- Do not confuse an identifier with authorization or a precise clock.