We need to design a distributed unique ID generator without collisions with time-ordered IDs and high throughput.
The hardest NFR is guaranteeing global uniqueness at high throughput without bottleneck.
Throughput scales horizontally by adding generator nodes, as ID generation is fully local.
POST /ids
Request: {"count": n}
Response: {"ids": [<id1>, <id2>, ..., <idn>]
Errors:
400 - invalid count
429 - rate limited
IDs are returned as strings and the API is stateless.
As seen on the diagram, there is no database.
There are no database calls.
The IDs are not stored.
The Load Balancer stores in memory mappings for (instance, node_id).
Per node: thousands of IDs/sec easily.
We can scale horizontally by adding generators.
The IDs are not strictly globally ordered but only time-ordered.
This trades perfect ordering for minimal synchronisation overhead.
We could:
Problem
How to generate globally unique IDs without central coordination while keeping the IDs roughly time-ordered.
Solution
We can use a Snowflake-style ID composed of:
Each generator node:
Trade-offs
Problem
We need to ensure that two nodes don't generate the same IDs by having the same node_id.
Solution
The Load Balancer:
Trade-offs