Unique ID generation: Snowflake, UUID, ticket servers
Every order, message and photo needs an ID, and once inserts happen on many machines, one database counter becomes a bottleneck and a single point of failure. The choices: a counter handing out ranges, random UUIDs, or time-ordered IDs like Snowflake that each machine makes alone. Interviewers want you to say which properties you need (size, order, guessability) and what your choice does to the database's index.
Raffle tickets at a school fair
A school fair sells raffle tickets from several stalls, and no two may share a number. Sellers could walk to the main desk for each number: one queue, and selling stops if the desk closes. Each stall could get a pre-printed book of 1,000 numbers in the morning. Each seller could write the time, their stall letter and a count, like "10:42-C-17". Or each could write a random number so long that two will never match.
- the stalls and their sellers → the app servers that insert rows
- the main desk → a central counter (a database sequence)
- a book of 1,000 numbers → range allocation (a ticket server)
- the stall letter → the machine ID, and time + stall + count → Snowflake-style IDs
- a very long random number → UUIDs