Sharding & Replication Questions with Answers

14 practice questions on Sharding & Replication (NoSQL & MongoDB) with answers and step-by-step solutions. Try 10 samples below, then practise all 14 free in the AptiNest app.

Sample questions

Question 1Easy

Horizontal scaling means:

  1. Adding RAM to one machine
  2. Adding more machines
  3. Adding indexes
  4. Compressing data

Answer: B. Adding more machines

Explanation

Scale-out spreads load across nodes.

Step-by-step solution

  1. Horizontal = more nodes.

Why the other options are wrong

  • A. Adding RAM to one machine is vertical scaling, not horizontal.
  • C. Adding indexes is unrelated to scaling out across machines.
  • D. Compression reduces storage, not horizontal scaling.

Question 2Easy

The main purpose of a replica set in MongoDB is:

  1. Scaling writes horizontally across many machines
  2. Reducing the size of each stored document
  3. High availability and redundancy through copies of data
  4. Creating indexes faster

Answer: C. High availability and redundancy through copies of data

Explanation

Replica sets keep copies and elect a new primary on failure.

Step-by-step solution

  1. Copies on several nodes.
  2. Failover through election.

Why the other options are wrong

  • A. Write scale-out is sharding.
  • B. Replica sets do not shrink documents; they copy data for redundancy.
  • D. Replica sets serve availability, not faster index creation.

Question 3Easy

What is a replica set in MongoDB?

  1. mongod instances holding the same data
  2. A shard key
  3. A type of index
  4. A backup file

Answer: A. mongod instances holding the same data

Explanation

Replica sets give redundancy and automatic failover.

Step-by-step solution

  1. A replica set is a group of mongod processes.
  2. Every member holds a copy of the same data, with one primary.
  3. So a replica set is mongod instances holding the same data; the correct answer is option A.

Why the other options are wrong

  • B. A shard key is used for sharding, not for replica sets.
  • C. An index is a separate feature.
  • D. A replica set is live copies of data, not a backup file.

Tip: Replicas copy data for safety and failover; sharding splits data for scale.

Question 4Medium

What is a chunk in a sharded MongoDB cluster?

  1. A single document inside a collection
  2. A replica member that holds a full copy of the data for failover
  3. An index structure built on the shard key
  4. A contiguous range of shard key values stored on one shard

Answer: D. A contiguous range of shard key values stored on one shard

Explanation

Chunks are the unit that the balancer migrates.

Step-by-step solution

  1. Range of shard keys.

Why the other options are wrong

  • A. Documents live in chunks.
  • B. A chunk is a key range, not a replica member.
  • C. A chunk is a range of shard key values, not an index structure.

Question 5Medium

What happens when the primary of a replica set becomes unreachable?

  1. The set stops forever
  2. A secondary is deleted
  3. The remaining members elect a new primary
  4. Clients write to all secondaries

Answer: C. The remaining members elect a new primary

Explanation

A majority vote promotes a secondary.

Step-by-step solution

  1. Heartbeats fail.
  2. Election.
  3. New primary.

Why the other options are wrong

  • A. It recovers automatically.
  • B. Secondaries are not deleted when the primary becomes unreachable.
  • D. Secondaries are read-only until promoted.

Question 6Medium

What is sharding?

  1. Copying all data to every node
  2. Compressing a collection on disk
  3. Splitting data across machines
  4. Creating a read-only index

Answer: C. Splitting data across machines

Explanation

Sharding is horizontal partitioning for scale beyond one server.

Step-by-step solution

  1. Sharding spreads one collection across several shards.
  2. Each shard holds a part of the data, often on different machines.
  3. So sharding is splitting data across machines; the correct answer is option C.

Why the other options are wrong

  • A. Copying all data to every node is replication.
  • B. Compressing a collection is a storage feature, not sharding.
  • D. A read-only index is not sharding.

Tip: Sharding = more machines share the data; replication = more copies of the same data.

Question 7Medium

In a replica set, which member accepts writes by default?

  1. Any secondary member
  2. The primary
  3. The arbiter member
  4. The config server

Answer: B. The primary

Explanation

Only the primary takes writes; secondaries replicate from it.

Step-by-step solution

  1. Primary handles all write operations in a replica set.
  2. Secondaries only read and replicate data.
  3. Arbiters do not accept writes or serve clients.
  4. Config servers manage configuration data, not user writes.
  5. The primary is the only member that accepts writes by default.

Why the other options are wrong

  • A. Secondaries copy the primary's data and do not take writes by default.
  • C. An arbiter only votes in elections and holds no data, so it cannot accept writes.
  • D. The config server stores cluster metadata in sharded setups; it is not a replica set member.

Tip: Remember: Only the primary accepts writes in a replica set.

Question 8Medium

Why is a monotonically increasing shard key (like a timestamp) a poor choice for range sharding?

  1. All new writes go to the same shard (hotspot)
  2. It cannot be indexed because timestamps change on every update
  3. It prevents replication
  4. It doubles storage

Answer: A. All new writes go to the same shard (hotspot)

Explanation

New values always fall in the highest range so one shard takes all inserts.

Step-by-step solution

  1. Ranges are contiguous.
  2. Newest range lives on one shard.

Why the other options are wrong

  • B. Timestamps can be indexed; the problem is concentrated writes.
  • C. A monotonic shard key does not stop replication.
  • D. A monotonic shard key does not double storage.

Tip: Hashed shard keys spread writes.

Question 9Hard

Which shard key choice is most likely to cause a hot shard?

  1. A hashed _id
  2. A high-cardinality random field
  3. A compound key with good spread
  4. A steadily increasing timestamp

Answer: D. A steadily increasing timestamp

Explanation

New inserts all land on the chunk with the highest range, overloading one shard.

Step-by-step solution

  1. A hot shard receives most of the reads or writes.
  2. A steadily increasing timestamp sends all new writes to the same range and shard.
  3. So a steadily increasing timestamp is most likely to cause a hot shard; the correct answer is option D.

Why the other options are wrong

  • A. A hashed _id spreads writes evenly across shards.
  • B. A high-cardinality random field spreads data well across shards.
  • C. A compound key with good spread avoids hot spots.

Tip: Avoid shard keys that always grow; choose keys with even spread.

Question 10Hard

In a sharded cluster, which component routes client operations to the right shards?

  1. mongod secondary
  2. config server
  3. arbiter
  4. mongos

Answer: D. mongos

Explanation

mongos is the query router; it consults config servers for metadata.

Step-by-step solution

  1. Clients connect to the router.
  2. Router knows chunk locations from config servers.

Why the other options are wrong

  • A. Secondary is a data node.
  • B. Config servers store metadata, not route.
  • C. Arbiters vote in elections; they do not route client operations.

Practise all 14 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 NoSQL & MongoDB topics · All topics