Sharding & Consistent Hashing Questions with Answers

20 practice questions on Sharding & Consistent Hashing (System Design) with answers and step-by-step solutions. Try 10 samples below, then practise all 20 free in the AptiNest app.

Sample questions

Question 1Easy

Vertical partitioning means:

  1. Replicating the table to a second region for disaster recovery
  2. Splitting rows across servers
  3. Splitting a table's columns into separate tables or stores
  4. Adding RAM to the database

Answer: C. Splitting a table's columns into separate tables or stores

Explanation

For example, keeping large rarely-used columns like a profile bio apart from hot columns.

Step-by-step solution

  1. Vertical partitioning splits a table by columns, not rows.
  2. Columns that are rarely used or large can move to a separate table or store.
  3. Hot columns stay together for fast access.
  4. So vertical partitioning splits a table's columns into separate tables or stores (option C).

Why the other options are wrong

  • A. Replicating to another region is disaster recovery, not partitioning.
  • B. Splitting rows across servers is horizontal partitioning or sharding.
  • D. Adding RAM is a hardware change, not a partitioning method.

Tip: Vertical partitioning = split by columns; horizontal partitioning = split by rows.

Question 2Easy

Sharding vs partitioning: which is the usual distinction?

  1. Sharding usually means partitions on different machines
  2. Partitioning always means vertical splitting of columns
  3. Sharding is only done in NoSQL databases, never in relational databases like MySQL
  4. They mean opposite things

Answer: A. Sharding usually means partitions on different machines

Explanation

Partitioning splits a table; sharding is the case where partitions live on separate servers.

Step-by-step solution

  1. Partitioning splits a table into parts.
  2. Sharding is the case where those parts live on separate servers.
  3. So a shard is a partition on a separate machine.
  4. So sharding usually means partitions on different machines (option A).

Why the other options are wrong

  • B. Partitioning can split rows or columns, so it is not always vertical.
  • C. Sharding is also done in relational databases such as MySQL.
  • D. They are related: sharding is one form of partitioning, so they do not mean opposite things.

Tip: Partitioning splits a table; sharding puts the parts on separate machines.

Question 3Easy

What is resharding?

  1. Rebuilding replicas from backups
  2. Running the same query on every shard in parallel and merging the results
  3. Recreating all indexes on one shard
  4. Moving data to a new shard layout as data or load grows

Answer: D. Moving data to a new shard layout as data or load grows

Explanation

Resharding redistributes data when shards fill up or become imbalanced; it is costly, so shard keys should be chosen carefully.

Step-by-step solution

  1. Resharding happens when shards fill up or become unbalanced.
  2. Data is moved to a new shard layout as the data or load grows.
  3. This is costly, so shard keys should be chosen with care.
  4. So resharding is moving data to a new shard layout (option D).

Why the other options are wrong

  • A. Rebuilding replicas from backups is a recovery task, not resharding.
  • B. Running a query on every shard and merging is scatter-gather.
  • C. Recreating indexes on one shard is maintenance, not resharding.

Tip: Resharding is costly, so choose the shard key well at the start.

Question 4Easy

Which statement best describes sharding a very large users table?

  1. Compressing tables to save space
  2. Caching query results in memory
  3. Splitting data across nodes so each holds a subset
  4. Copying the full dataset to every node so any node can answer any query

Answer: C. Splitting data across nodes so each holds a subset

Explanation

Sharding (horizontal partitioning) spreads rows across machines so storage and write load scale out.

Step-by-step solution

  1. Sharding splits a very large table across machines.
  2. Each node holds a subset of the rows.
  3. So storage and write load can scale out.
  4. So sharding splits data across nodes so each holds a subset (option C).

Why the other options are wrong

  • A. Compression saves space but does not spread rows across machines.
  • B. Caching query results is a different technique.
  • D. Copying the full dataset to every node is replication, not sharding.

Tip: Sharding spreads rows across machines so storage and writes scale out.

Question 5Medium

A social app shards by user_id. A celebrity's posts receive enormous traffic on one shard. What is this problem called?

  1. A hot partition (hot key)
  2. A cold start
  3. Phantom read caused by the repeatable-read isolation level
  4. Write skew

Answer: A. A hot partition (hot key)

Explanation

Skewed access concentrates load on one shard; fixes include caching, splitting the key or adding salt.

Step-by-step solution

  1. Sharding by user_id puts one user's posts on one shard.
  2. A celebrity's traffic all lands on that single shard.
  3. One overloaded key or partition is a hot partition.
  4. So the problem is a hot partition, also called a hot key (option A).

Why the other options are wrong

  • B. A cold start is a term for a system with no warm cache or state, not this case.
  • C. A phantom read is an isolation anomaly, not a traffic hotspot.
  • D. Write skew is a concurrency anomaly, not a traffic hotspot.

Tip: A hot key sends too much traffic to one shard; fix with caching, salting or splitting the key.

Question 6Medium

What makes a good shard key?

  1. The row's creation timestamp alone, because time always increases evenly
  2. High cardinality, even spread, and alignment with common queries
  3. A column that changes on every update
  4. A boolean column such as is_active

Answer: B. High cardinality, even spread, and alignment with common queries

Explanation

Low-cardinality or monotonically increasing keys create hot shards; queries should usually hit one shard.

Step-by-step solution

  1. A good shard key has many distinct values, which is high cardinality.
  2. It spreads rows evenly across shards.
  3. It matches the common queries so each query hits one shard.
  4. So option B describes a good shard key (option B).

Why the other options are wrong

  • A. A timestamp alone rises steadily, so new writes hit one shard and create a hotspot.
  • C. A column that changes on every update makes rows move or cause churn and is not a stable key.
  • D. A boolean has only two values, so it cannot spread data across many shards.

Tip: Pick a shard key with many values, even spread and match to the main query.

Question 7Medium

Consistent hashing with replication typically stores a key on:

  1. Only its owner node
  2. All nodes in the cluster so that any one of them can answer a read without forwarding
  3. Its owner node plus the next few distinct nodes clockwise
  4. A random node chosen per write

Answer: C. Its owner node plus the next few distinct nodes clockwise

Explanation

Walking clockwise to the next R distinct physical nodes gives replicas that are easy to locate.

Step-by-step solution

  1. Replicated consistent hashing stores each key on its owner node.
  2. It also copies the key to the next few distinct nodes clockwise.
  3. Walking clockwise makes the replicas easy to find.
  4. So the key is stored on its owner plus the next few distinct nodes clockwise (option C).

Why the other options are wrong

  • A. Storing only on the owner is no replication.
  • B. Storing on all nodes is full replication, not consistent-hash replication.
  • D. A random node per write would make replicas hard to locate.

Tip: Consistent-hash replication: owner node plus the next distinct nodes clockwise.

Question 8Medium

In a Snowflake-style ID, 12 bits are a per-millisecond sequence. How many IDs can one machine generate per millisecond?

  1. 4,096
  2. 4,095,000
  3. 1,024
  4. 12

Answer: A. 4,096

Explanation

2^12 = 4,096
sequence values per millisecond per worker.

Step-by-step solution

  1. A 12-bit sequence has 2^12 possible values.
  2. 2^12 = 4,096.
  3. So one worker can issue 4,096 IDs per millisecond.
  4. So the answer is 4,096 (option A).

Why the other options are wrong

  • B. 4,095,000 has no link to 12 bits; the sequence holds 4,096 values per millisecond.
  • C. 1,024 is 2^10, not 2^12.
  • D. 12 is the bit count, not the number of IDs.

Tip: N bits hold 2^n values; 12 bits give 4,096.

Question 9Hard

Why do consistent-hashing systems use virtual nodes (vnodes)?

  1. To let one key live on several unrelated rings
  2. To make the ring order keys alphabetically so range scans become cheap
  3. To spread each server across many ring points for balance
  4. To remove the need for replication

Answer: C. To spread each server across many ring points for balance

Explanation

With few physical nodes, ring arcs are uneven; many virtual points per server smooth the load and spread a failed node's data over many peers.

Step-by-step solution

  1. With few physical nodes, the ring arcs can be uneven.
  2. Each server gets many virtual points on the ring.
  3. That evens the load and spreads a failed node's data over many peers.
  4. So vnodes spread each server across many ring points (option C).

Why the other options are wrong

  • A. A key lives on one ring position owner set, not on unrelated rings.
  • B. Vnodes do not sort keys alphabetically; hashing scatters them.
  • D. Vnodes do not remove the need for replication.

Tip: Virtual nodes smooth the load on a consistent-hash ring.

Question 10Hard

A Snowflake-style 64-bit ID uses 41 bits for milliseconds since a custom epoch. About how long until it overflows?

  1. About 24 days
  2. About 136 years
  3. About 41 years
  4. About 69 years

Answer: D. About 69 years

Explanation

2^41 ms ≈ 2.2 × 10^12 ms
≈ 69.7 years.

Step-by-step solution

  1. 41 bits count milliseconds, so the maximum is 2^41 ms.
  2. 2^41 ms is about 2.2 × 10^12 ms, which is about 2.2 × 10^9 seconds.
  3. Divided by about 31.56 million seconds a year, that is about 69.7 years.
  4. So it overflows in about 69 years (option D).

Why the other options are wrong

  • A. 24 days would need only about 31 bits of milliseconds, not 41.
  • B. 136 years does not match 2^41 ms; the answer is about 69.
  • C. 41 is the bit count, not the number of years.

Tip: Years = 2^bits ms ÷ 1000 ÷ 31,557,600 seconds a year.

Practise all 20 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all System Design topics · All topics