A shard key is a specific field or set of fields used to divide data into smaller parts called shards. It helps distribute data across multiple servers to improve performance and scalability.
Click to reveal answer
beginner
Why is choosing the right shard key important?
The right shard key ensures even data distribution, reduces hotspots, and improves query performance. A poor choice can cause uneven load and slow down the system.
Click to reveal answer
intermediate
What are common criteria for selecting a shard key?
Common criteria include high cardinality (many unique values), frequent use in queries, even data distribution, and low update frequency to avoid moving data between shards.
Click to reveal answer
intermediate
Explain the impact of a low-cardinality shard key.
A low-cardinality shard key has few unique values, causing data to cluster in few shards. This leads to uneven load, hotspots, and poor scalability.
Click to reveal answer
intermediate
What is a hotspot in sharding, and how does shard key selection affect it?
A hotspot is a shard that receives a disproportionate amount of traffic or data. Choosing a shard key that evenly distributes data and queries helps prevent hotspots.
Click to reveal answer
Which property is most important for a shard key to ensure even data distribution?
AHigh cardinality
BLow update frequency
CUsed in rare queries
DSmall data size
✗ Incorrect
High cardinality means many unique values, which helps distribute data evenly across shards.
What happens if a shard key causes data to cluster on a few shards?
AImproved query speed
BHotspots and uneven load
CAutomatic data balancing
DReduced storage needs
✗ Incorrect
Clustering data on few shards creates hotspots, causing uneven load and performance issues.
Which shard key characteristic helps reduce data movement between shards?
AUsed only in writes
BHigh update frequency
CLow update frequency
DRandom values
✗ Incorrect
Low update frequency means shard key values rarely change, reducing data movement between shards.
Why should a shard key be frequently used in queries?
ATo avoid data partitioning
BTo increase data duplication
CTo reduce shard count
DTo improve query routing and performance
✗ Incorrect
Using the shard key in queries helps route queries directly to relevant shards, improving performance.
Which of these is NOT a good shard key choice?
ACountry code with 3-4 unique values
BUser ID with millions of unique users
COrder ID with unique values
DSession token with high uniqueness
✗ Incorrect
Country code has low cardinality, causing uneven data distribution and hotspots.
Explain how to select a shard key for a large user database.
Think about what uniquely identifies users and how queries are made.
You got /4 concepts.
Describe the consequences of a poor shard key choice in a distributed system.
Consider what happens when data is not balanced across servers.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of selecting a shard key in a distributed database system?
easy
A. To compress data to save storage space
B. To encrypt data for security purposes
C. To backup data automatically
D. To split data across servers for better load distribution and faster access
Solution
Step 1: Understand shard key role
The shard key determines how data is divided across multiple servers or shards.
Step 2: Identify main benefit
Splitting data helps balance load and speeds up data retrieval by parallelizing queries.
Final Answer:
To split data across servers for better load distribution and faster access -> Option D
Quick Check:
Shard key purpose = split data load [OK]
Hint: Shard key splits data to spread load and speed up access [OK]
Common Mistakes:
Confusing shard key with encryption key
Thinking shard key compresses data
Assuming shard key is for backup
2. Which of the following is a good characteristic of a shard key?
easy
A. Has very few unique values
B. Has many unique values and distributes data evenly
C. Is always a timestamp
D. Is a large text field
Solution
Step 1: Identify shard key traits
A good shard key should have many unique values to avoid data concentration.
Step 2: Understand distribution importance
Even distribution prevents hotspots and balances load across shards.
Final Answer:
Has many unique values and distributes data evenly -> Option B
Quick Check:
Good shard key = unique + even distribution [OK]
Hint: Choose shard keys with many unique values and even spread [OK]
Common Mistakes:
Picking keys with few unique values causing hotspots
Assuming timestamp is always best shard key
Using large text fields that slow down indexing
3. Consider a user database sharded by country_code which has only 5 unique values. What is the likely problem with this shard key?
medium
A. Data will be evenly distributed across shards
B. It will encrypt user data automatically
C. Some shards will be overloaded due to uneven data distribution
D. Queries will be faster because of fewer shards
Solution
Step 1: Analyze unique values count
Only 5 unique values means few shards and many users per shard.
Step 2: Understand load distribution
Popular countries will have more users, causing some shards to be overloaded.
Final Answer:
Some shards will be overloaded due to uneven data distribution -> Option C
Quick Check:
Few unique keys = uneven shard load [OK]
Hint: Few unique shard keys cause uneven load and hotspots [OK]
Common Mistakes:
Assuming fewer shards always improve speed
Thinking shard key encrypts data
Ignoring uneven data distribution effects
4. A system uses user_id % 10 as a shard key but notices uneven shard sizes. What is the likely cause?
medium
A. User IDs are not uniformly distributed modulo 10
B. Shard key is too unique
C. Shard key is a string instead of number
D. System is encrypting shard keys
Solution
Step 1: Understand modulo shard key
Modulo operation expects uniform distribution of user IDs.
Step 2: Identify distribution problem
If user IDs cluster in certain ranges, modulo results cluster causing uneven shards.
Final Answer:
User IDs are not uniformly distributed modulo 10 -> Option A
Quick Check:
Non-uniform IDs cause uneven modulo shard keys [OK]
Hint: Modulo shard keys need uniform input distribution [OK]
Common Mistakes:
Assuming modulo always balances shards
Confusing shard key type with encryption
Ignoring data distribution patterns
5. You design a sharded system for an e-commerce app. Users query orders mostly by user_id and order_date. Which shard key choice best supports fast queries and balanced load?
hard
A. Shard by a composite key of user_id and order_date
B. Shard by user_id only
C. Shard by order_date only
D. Shard by a random UUID
Solution
Step 1: Match shard key to query patterns
Users query by both user_id and order_date, so shard key should support both.
Step 2: Evaluate shard key options
Sharding by user_id alone may cause hotspots; order_date alone may cause uneven load by time.
Step 3: Use composite key benefits
Composite key balances load and supports queries filtering by either field efficiently.
Final Answer:
Shard by a composite key of user_id and order_date -> Option A
Quick Check:
Composite shard key matches queries and balances load [OK]
Hint: Composite keys balance load and match query patterns best [OK]
Common Mistakes:
Choosing single field shard keys ignoring query patterns
Using random UUID causing inefficient queries
Ignoring load balancing in shard key choice
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.