Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo DB - difference between standalone & 1-node replica set

I needed to use Mongo DB transactions, and recently I understood that transactions don't work for Mongo standalone mode, but only for replica sets (Mongo DB with C# - document added regardless of transaction).
Also, I read that standalone mode is not recommended for production.

So I found out that simply defining a replica set name in the mongod.cfg is enough to run Mongo DB as a replica set instead of standalone.
After changing that, Mongo transactions started working.
However, it feels a bit strange using it as replica-set although I'm not really using the replication functionality, and I want to make sure I'm using a valid configuration.

So my questions are:

  1. Is there any problem/disadvantage with running Mongo as a 1-node replica set, assuming I don't really need the replication, load balancing or any other scalable functionality? (as said I need it to allow transactions)
  2. What are the functionality and performance differences, if any, between running as standalone vs. running as a 1-node replica set?
  3. I've read that standalone mode is not recommended for production, although it sounds like it's the most basic configuration. I understand that this configuration is not used in most scenarios, but sometimes you may want to use it as a standard DB on a local machine. So why is standalone mode not recommended? Is it not stable enough, or other reasons?
like image 644
Metheny Avatar asked May 28 '19 06:05

Metheny


People also ask

What is a MongoDB replica set?

In simple terms, MongoDB replication is the process of creating a copy of the same data set in more than one MongoDB server. This can be achieved by using a Replica Set. A replica set is a group of MongoDB instances that maintain the same data set and pertain to any mongod process.

What is sharding and replication in MongoDB?

What is the difference between replication and sharding? Replication: The primary server node copies data onto secondary server nodes. This can help increase data availability and act as a backup, in case if the primary server fails. Sharding: Handles horizontal scaling across servers using a shard key.

What is Oplog in MongoDB?

The Oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. MongoDB applies database operations on the primary and then records the operations on the primary's oplog.


1 Answers

Is there any problem/disadvantage with running Mongo as a 1-node replica set, assuming I don't really need the replication, load balancing or any other scalable functionality?

You don't have high availability afforded by a proper replica set. Thus it's not recommended for a production deployment. This is fine for development though.

Note that a replica set's function is primarily about high availability instead of scaling.

What are the functionality and performance differences, if any, between running as standalone vs. running as a 1-node replica set?

A single-node replica set would have the oplog. This means that you'll use more disk space to store the oplog, and also any insert/update operation would be written to the oplog as well (write amplification).

So why is standalone mode not recommended? Is it not stable enough, or other reasons?

MongoDB in production was designed with a replica set deployment in mind, for:

  • High availability in the face of node failures
  • Rolling maintenance/upgrades with no downtime
  • Possibility to scale-out reads
  • Possibility to have a replica of data in a special-purpose node that is not part of the high availability nodes

In short, MongoDB was designed to be a fault-tolerant distributed database (scales horizontally) instead of the typical SQL monolithic database (scales vertically). The idea is, if you lose one node of your replica set, the others will immediately take over. Most of the time your application don't even know there's a failure in the database side. In contrast, a failure in a monolithic database server would immediately disrupt your application.

like image 100
kevinadi Avatar answered Sep 17 '22 11:09

kevinadi