10. Unique ID Generation
1
The picture to keep in your head2
10.1 What makes a good ID?3
10.2 What's wrong with auto-increment?4
10.3 Why does auto-increment break across many servers?5
10.4 What are UUIDs, and which version should you use?6
10.5 How do Snowflake IDs work?7
10.6 What are ticket servers and ID ranges?8
10.7 Why does clock skew matter for time-based IDs?9
10.8 How do you make short IDs with base62?10
10.9 Should IDs be guessable or unguessable?11
Memory card and where the analogy breaks12
Practice: five levels13
Interview questions14
Solutions15
Sources16
Code lab10. Unique ID Generation
Sources
3 min read+10 XP
Source notes
- UUID versions 4 and 7, bit layouts: RFC 9562, "Universally Unique IDentifiers (UUIDs)", May 2024 (replaces RFC 4122). Python's standard library added
uuid.uuid7()in Python 3.14 (Python documentation). - Snowflake: Twitter Engineering, "Announcing Snowflake", June 2010, and the original open-source project (twitter-archive/snowflake on GitHub): 41-bit timestamp, 10-bit machine ID, 12-bit sequence; refuses to generate when the clock moves backwards.
- Ticket servers with step and offset: Flickr Code blog, "Ticket Servers: Distributed Unique Primary Keys on the Cheap", February 2010.
- Instagram's ID scheme (41 bits time, 13 bits shard, 10 bits sequence, generated in PostgreSQL): Instagram Engineering, "Sharding & IDs at Instagram", 2012.
- Insecure direct object reference (IDOR): OWASP guidance on broken access control.
- Birthday-bound collision figures for UUID v4 and all other arithmetic: computed 2026-10-08.
- Level 3 and Level 4 code: tested 2026-10-08 (
code/ch10_ids.py, all checks pass).