Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main purpose of a unique ID generator in system design?
To create identifiers that are unique across the system, ensuring no two entities share the same ID, which helps in tracking, referencing, and managing data reliably.
Click to reveal answer
intermediate
Name two common approaches to generate unique IDs in distributed systems.
1. Using timestamp-based IDs combined with machine identifiers (e.g., Snowflake algorithm). 2. Using Universally Unique Identifiers (UUIDs) which are random or pseudo-random.
Click to reveal answer
beginner
Why is it important to avoid collisions in unique ID generation?
Collisions cause two different entities to have the same ID, leading to data corruption, overwriting, or incorrect data retrieval, which breaks system integrity.
Click to reveal answer
intermediate
What role does scalability play in designing a unique ID generator?
The generator must handle increasing load and number of requests without slowing down or producing duplicates, ensuring consistent performance as the system grows.
Click to reveal answer
advanced
Explain the concept of 'sharding' in the context of unique ID generation.
Sharding means dividing the ID generation responsibility across multiple nodes or machines, each generating IDs in a specific range or with unique prefixes to avoid collisions.
Click to reveal answer
Which of the following is a common method to ensure uniqueness in distributed ID generation?
AUsing only random numbers without coordination
BCombining timestamp with machine ID
CAssigning IDs manually by users
DReusing IDs after deletion
✗ Incorrect
Combining timestamp with machine ID helps create unique IDs across machines and time, reducing collisions.
What is a UUID primarily used for?
AEncrypting data
BManaging user sessions
CCompressing files
DGenerating globally unique identifiers
✗ Incorrect
UUIDs are designed to generate unique identifiers that are globally unique without central coordination.
Why might a simple auto-increment ID not be suitable for distributed systems?
AIt requires central coordination which can be a bottleneck
BIt is too random
CIt uses too much memory
DIt is not human-readable
✗ Incorrect
Auto-increment IDs need a central source to assign IDs sequentially, which can slow down or fail in distributed setups.
What does 'collision' mean in unique ID generation?
AAn ID is not encrypted
BAn ID is too long
CTwo IDs are the same for different entities
DAn ID is generated slowly
✗ Incorrect
Collision means two different entities get assigned the same ID, which causes errors.
Which property is NOT essential for a good unique ID generator?
APredictability
BScalability
CUniqueness
DLow latency
✗ Incorrect
Predictability is usually avoided to prevent security risks; uniqueness, scalability, and low latency are essential.
Describe the key components and flow of a distributed unique ID generator system.
Think about how different parts work together to create unique IDs without conflicts.
You got /5 concepts.
Explain the trade-offs between using UUIDs and timestamp-based IDs like Snowflake for unique ID generation.
Consider uniqueness, readability, and system requirements.
You got /4 concepts.
Practice
(1/5)
1. What is the primary purpose of a unique ID generator in a distributed system?
easy
A. To create identifiers that are distinct across all machines and time
B. To encrypt data for secure communication
C. To compress large files efficiently
D. To balance load between servers
Solution
Step 1: Understand the role of unique IDs
Unique IDs ensure that each identifier is different from others, avoiding conflicts.
Step 2: Recognize distributed system needs
In distributed systems, IDs must be unique across machines and time to prevent collisions.
Final Answer:
To create identifiers that are distinct across all machines and time -> Option A
Quick Check:
Unique ID purpose = distinct identifiers [OK]
Hint: Unique IDs prevent duplicates across systems [OK]
Common Mistakes:
Confusing unique ID with encryption
Thinking unique ID compresses data
Mixing load balancing with ID generation
2. Which of the following is a common component in a unique ID generator design?
easy
A. Encryption key for data security
B. Load balancer to distribute requests
C. Compression algorithm for data size reduction
D. Sequence number to avoid collisions within the same timestamp
Solution
Step 1: Identify components of unique ID generators
Common components include timestamp, machine identifier, and sequence number.
Step 2: Understand sequence number role
Sequence numbers help generate multiple unique IDs within the same timestamp to avoid collisions.
Final Answer:
Sequence number to avoid collisions within the same timestamp -> Option D
Quick Check:
Sequence number = collision avoidance [OK]
Hint: Sequence numbers prevent same-time ID clashes [OK]
Common Mistakes:
Confusing encryption with ID generation
Thinking compression is part of ID design
Mixing load balancing with ID components
3. Consider a unique ID generator that uses a 41-bit timestamp, 10-bit machine ID, and 12-bit sequence number. What is the maximum number of unique IDs it can generate per millisecond per machine?
medium
A. 8192
B. 1024
C. 4096
D. 2048
Solution
Step 1: Understand bit allocation for sequence number
The sequence number uses 12 bits, so max IDs per millisecond = 2^12.
Step 2: Calculate 2^12
2^12 = 4096 unique IDs per millisecond per machine.
Final Answer:
4096 -> Option C
Quick Check:
2^12 = 4096 [OK]
Hint: 2^sequence_bits = max IDs/ms [OK]
Common Mistakes:
Using machine ID bits instead of sequence bits
Calculating 2^10 or 2^11 instead of 2^12
Confusing total bits with sequence bits
4. A unique ID generator uses a timestamp, machine ID, and sequence number. If two machines generate IDs at the exact same millisecond with the same sequence number, what is the likely cause of duplicate IDs?
medium
A. Machine IDs are not unique or not included in the ID
B. Timestamp is too large
C. Sequence number is too long
D. The system uses encryption
Solution
Step 1: Analyze ID components for uniqueness
Machine ID differentiates IDs from different machines at the same time.
Step 2: Identify cause of duplicates
If machine IDs are missing or not unique, IDs from different machines can collide.
Final Answer:
Machine IDs are not unique or not included in the ID -> Option A
Quick Check:
Missing unique machine ID = duplicates [OK]
Hint: Unique machine ID prevents cross-machine duplicates [OK]
Common Mistakes:
Blaming timestamp size for duplicates
Thinking longer sequence number causes duplicates
Confusing encryption with ID uniqueness
5. You need to design a unique ID generator for a global system with thousands of machines generating millions of IDs per second. Which design choice best ensures scalability and uniqueness?
hard
A. Generate random 64-bit numbers without coordination
B. Use a 64-bit ID combining timestamp, machine ID, and sequence number with synchronized clocks
C. Use only timestamp-based IDs without machine info
D. Assign IDs sequentially from a central server
Solution
Step 1: Consider scalability and uniqueness needs
Global scale requires IDs unique across machines and time, with high throughput.
Step 2: Evaluate design options
Combining timestamp, machine ID, and sequence number in 64 bits with synchronized clocks ensures uniqueness and scalability.
Step 3: Reject other options
Random IDs risk collisions; timestamp-only lacks machine uniqueness; central server causes bottleneck.
Final Answer:
Use a 64-bit ID combining timestamp, machine ID, and sequence number with synchronized clocks -> Option B
Quick Check:
64-bit composite ID = scalable unique IDs [OK]
Hint: Combine time, machine, sequence for scalable unique IDs [OK]