0
0
HLDsystem_design~20 mins

Shard key selection in HLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shard Key Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding shard key impact on data distribution

Imagine you have a large database storing user profiles. You want to split this data across multiple servers (shards) to improve performance. Which shard key choice will most evenly distribute the data?

AUser's country code (e.g., US, IN, UK)
BUser's signup date (YYYY-MM-DD)
CUser's unique ID (a random UUID)
DUser's last name initial (A-Z)
Attempts:
2 left
💡 Hint

Think about which key has the most randomness and uniqueness to spread data evenly.

Architecture
intermediate
2:00remaining
Choosing shard key for query efficiency

You design a product catalog system where users often search products by category and price range. Which shard key will optimize query speed for these searches?

AProduct category
BProduct creation timestamp
CProduct ID
DProduct price
Attempts:
2 left
💡 Hint

Consider which shard key aligns with common query filters to reduce cross-shard queries.

scaling
advanced
2:00remaining
Handling shard key hotspots in a social media app

A social media app uses user ID as the shard key. Suddenly, a celebrity user causes a hotspot with millions of requests to their shard. What is the best architectural approach to reduce this hotspot?

AImplement a cache layer in front of the database for popular user data
BChange shard key to user location to spread load geographically
CIncrease the number of shards without changing the shard key
DUse a composite shard key combining user ID and request timestamp
Attempts:
2 left
💡 Hint

Think about reducing load on the hotspot shard without major data reshuffling.

tradeoff
advanced
2:00remaining
Tradeoffs of choosing a monotonically increasing shard key

What is a major downside of using a monotonically increasing value (like timestamp or auto-increment ID) as a shard key?

AIt prevents horizontal scaling of the database
BIt increases network latency between shards
CIt makes data replication impossible
DIt causes uneven data distribution leading to shard hotspots
Attempts:
2 left
💡 Hint

Consider how new data is assigned to shards over time.

estimation
expert
3:00remaining
Estimating shard count for expected load

You expect 1 billion user records growing by 10 million per month. Each shard can handle 100 million records efficiently. How many shards do you need initially and after 6 months?

AInitially 5 shards; after 6 months 11 shards
BInitially 10 shards; after 6 months 16 shards
CInitially 15 shards; after 6 months 20 shards
DInitially 8 shards; after 6 months 14 shards
Attempts:
2 left
💡 Hint

Divide total records by shard capacity to estimate shard count.