01 / 11

Discuss replication in MongoDB?

Difficulty: 6/10
Replica sets, Read preferences, Failover

Replication in MongoDB is a process that ensures data is duplicated and consistently synchronized across multiple servers. It enhances data availability, fault tolerance, and system resilience in case of hardware failures or network issues.

  1. 1

    In some cases, replication can provide increased read capacity as clients can send read operations to different servers.

  2. 2

    MongoDB uses replica sets for replication. A replica set is a group of MongoDB servers that maintain the same data set.

Scenario Questions

0-2 years experience

  1. 1We need a replica set for a small web app. How would you configure the members and ensure reads can be served from secondaries?
  2. 2If a secondary falls behind the primary, what will happen when it catches up?
  3. 3Which read preference would you pick for a read‑heavy feature and why?

2-5 years experience

  1. 1Your team sees write timeouts during a primary election. Walk me through how you would debug the issue.
  2. 2You have to add a new secondary to an existing replica set without downtime. What steps would you take?
  3. 3Explain the trade‑offs between using 'majority' versus 'w:1' write concern for a low‑latency microservice that still needs durability.

5-8 years experience

  1. 1Design a high‑availability data layer for a global e‑commerce platform using MongoDB replication. How would you handle cross‑region latency, failover, and read/write routing?
  2. 2What are the implications of network partitions on a replica set, and how would you mitigate split‑brain scenarios?
  3. 3If you observe high replication lag during peak traffic, what architectural changes could you make to reduce it?

8+ years experience

  1. 1Your company is migrating from a sharded cluster with replica sets to a multi‑cloud deployment. How would you restructure replication to maintain consistency and meet SLA across providers?
  2. 2Discuss a long‑term maintenance strategy for replica set configurations when dozens of teams deploy independent services on the same cluster.
  3. 3How would you evaluate replacing MongoDB's built‑in replication with an external consensus system like etcd for certain critical data paths?

Follow-up Questions

  • What happens to pending writes when the primary steps down?
  • How does the choice of write concern impact latency and durability?
  • Can you describe a scenario where a read preference could cause stale data to be returned?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.