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

对着背影说爱祢 提交于 2020-12-24 15:50:19

问题


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?

回答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?

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.




回答2:


I think kevinadi answered well, but I still want to add it.

A standalone is an instance of mongod that runs on a single server but is not part of a replica set. Standalone instances used for testing and development, but always recomended to use replica sets in production.

A single-node replica set would have the oplog which records all changes to its data sets . 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). It also supports point in time recovery.

Please follow Convert a Standalone to a Replica Set if you would like to convert the standalone database to replicaset.

Transactions have been introduced in MongoDB version 4.0. Starting in version 4.0, for situations that require atomicity for updates to multiple documents or consistency between reads to multiple documents, MongoDB provides multi-document transactions for replica sets. The transaction is not available in standalone because it requires oplog to maintain strong consistency within a cluster.



来源:https://stackoverflow.com/questions/56336101/mongo-db-difference-between-standalone-1-node-replica-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!