Design a distributed Unique ID Generator (like Twitter Snowflake).
Code Playground
JavaScript (V8)
Loading...
Console Output
// Output will appear here...
// For React: ReactDOM.createRoot(rootElement).render(<App />);
// For React: ReactDOM.createRoot(rootElement).render(<App />);
Recommended Answer
System Design Scenario:
1. Goal: Generate 64-bit numeric IDs roughly sorted by time.
2. Structure (Snowflake approach):
* 1 bit: Sign bit (0).
* 41 bits: Timestamp (milliseconds since epoch).
* 10 bits: Machine ID (datacenter ID + worker ID).
* 12 bits: Sequence number (reset every millisecond).
3. Implementation:
* No coordination needed between nodes.
* IDs are k-sortable.