What is MongoDB Replication

By Sruthy

By Sruthy

Sruthy, with her 10+ years of experience, is a dynamic professional who seamlessly blends her creative soul with technical prowess. With a Technical Degree in Graphics Design and Communications and a Bachelor’s Degree in Electronics and Communication, she brings a unique combination of artistic flair…

Learn about our editorial policies.
Updated March 7, 2024

Replication in MongoDB:

In this Free MongoDB Training Series, we learned more about Sharding in MongoDB in our previous tutorial.

This tutorial will explain about Replication in MongoDB in detail.

In MongoDB, the replica set is a collection of active MongoDB instances which maintain the same data. The replica is used to enhance the visibility and availability of data. In order to prevent natural disasters replica is the best approach.

18. REPLICATION IN MONGODB

In simple words, the same information is hosted on different servers which are located at different locations. If one of those servers gets down due to any reason like a natural disaster or power fail-over, it will automatically sync with other servers having the same data.

Replication Architecture

In replication, each copy of the MongoDB instance is treated as a node. One of those nodes become the primary node and the rest of it becomes a secondary node.

Figure 1

Replication in MongoDB - Overview

Basically, the client is interacting with the primary node and the primary node is interacting with the secondary nodes automatically. If a client changes any information in the primary node, then it will automatically be replicated on secondary nodes.

If the primary node is not responsive then the secondary node automatically becomes the primary and the rest of the architecture will be the same.

With this architecture, the user will never get to know what actually happens. Replication architecture will maintain a smooth user interaction. This approach is used by many Tech Giants like Facebook, Google, LinkedIn, and Twitter.

You will never face any failover on these Tech Giants applications. Because they are using replication architecture approaches to enhance the visibility of the information for their end user. This approach is really beneficial for backup and disaster recovery.

In replication architecture, we have to understand that only the primary node will perform write and read operation. However, the rest of the secondary nodes will never perform write operation directly but they will entertain the read operations directly.

Replication is mostly used for big data and for the data center. If you are running “SAAS applications” then it will be really beneficial for you to implement replication architecture to enhance the availability of your data for the long run.

Figure 2

Replication Architecture in MongoDB

Sharding and replication are similar but have a different context. Both the architecture approaches are used to secure the information. However, it depends upon the requirement as which approach is beneficial. Some of the developers used the hybrid approach by developing the architecture between sharding and replication.

Conclusion

Replication is the process to replicate a single instance of the database on multiple servers. It is a kind of cluster of databases. Each node of the database is treated as a child node and one of them is treated as a parent node. A parent node has all the access and child node has limited access only.

Whenever parent node collapse, it will automatically shift to the child node as in this case the user never identified what happened in the backend process.

The best part of replication in MongoDB is that, it is transparent from the application and whatever the process happens in the backend process the connected collide will never know that.

Take a look at our upcoming tutorial to know the ways to Create Backup in MongoDB!!

PREV Tutorial | NEXT Tutorial

Was this helpful?

Thanks for your feedback!

Leave a Comment