SevyDevy

Design a unique ID generator like snowflake

PremiumDistributed infrastructureEasy

  • Snowflake ID
  • 64 bit IDs
  • Worker ID assignment

Quick answer

This distributed infrastructure interview question asks you to design a unique ID generator like snowflake. Aim for a design that keeps working across many machines and failures, then explain partitioning, replication, coordination and trade-offs. Interviewers want to see how you reason about failures, consistency and scale.

The problem

Design a unique ID generator like Snowflake that gives every service 64-bit IDs without a central database. Each ID packs a timestamp, a worker ID and a sequence number, so IDs are unique and roughly time-sorted. The hard parts are the bit layout, unique worker IDs, and staying correct when the sequence runs out or the clock goes backwards.

IDs are used as primary keys for orders, messages and events, so a duplicate ID is a data corruption bug.

What must a unique ID generator like snowflake do?

  • Unique 64-bit IDs: Every ID fits in a signed 64-bit integer and is never issued twice.
  • Time ordered: IDs from one generator always increase; across generators they sort roughly by creation time.
3 more requirementsUnlock to see all

How well must it do it?

  • Uniqueness: Zero duplicates, even when clocks misbehave or generators restart.
  • Latency: Under 1 ms at p99 per ID or batch.
2 more requirementsUnlock to see all

What scale should you design for?

Use these numbers in your estimates.

The scale numbers unlock with this questionUnlock

Key concepts

  • Snowflake ID
  • 64 bit IDs
  • Worker ID assignment
  • Sequence overflow
  • Clock skew
  • K sorted IDs

How you’ll practise

6 short steps · save and come back any time
  1. Requirements
  2. Estimate
  3. Data model and API
  4. Partitioning and replication
  5. Consistency and failures
  6. Wrap-up

Lala, personalized to you, gives a hint when you ask and reviews your design when you are ready.

What do interviewers look for?

In any distributed infrastructure design round.

  • States the consistency and availability guarantees up front
  • Explains partitioning and replication choices
  • Describes how nodes agree and recover after failures
  • Handles network partitions and slow nodes
  • Plans for adding and removing capacity safely
  • Names the trade-offs instead of hiding them

Questions people ask about this interview question

Which design type is this question?
It is a distributed infrastructure question. You design a unique ID generator like snowflake and explain your choices the way you would in an interview.
Is this question asked at entry level?
It is marked Easy, so it suits engineers who are new to distributed infrastructure interviews. It is also a good warm-up before harder questions.
What should I cover first?
Start with the guarantees the system must give and the failures it must survive. Agree on scope with the interviewer before you design anything.
Can I practise it for free?
It is a premium question. Sign up and unlock it once for 10 credits; it then stays unlocked. When you finish, Lala, your personalized AI mentor, can review your design for 30 credits.

Related questions

Updated · Written by the SevyDevy team

Premium questionSign up free, then unlock it