- Mastering MongoDB 3.x
- Alex Giamas
- 275字
- 2021-08-20 10:10:47
Best practices for replication
Replica sets are MongoDB's mechanism to provide redundancy, high availability, and higher read throughput under the right conditions. Replication in MongoDB is easy to configure and light in operational terms:
- Always use replica sets: Even if your dataset is at the moment small and you don't expect it to grow exponentially, you never know when that might happen. Also, having a replica set of at least three servers helps design for redundancy, separating work loads between real time and analytics (using the secondaries) and having data redundancy built from day one.
- Use a replica set to your advantage: A replica set is not just for data replication. We can and should in most cases use the primary server for writes and preference reads from one of the secondaries to offload the primary server. This can be done by setting read preference for reads, together with the correct write concern to ensure writes propagate as needed.
- Use an odd number of replicas in a MongoDB replica set: If a server does down or loses connectivity with the rest of them (network partitioning), the rest have to vote as to which one will be elected as the primary server. If we have an odd number of replica set members, we can guarantee that each subset of servers knows if they belong to the majority or the minority of the replica set members. If we can't have an odd number of replicas, we need to have one extra host set as an arbiter with the sole purpose of voting in the election process. Even a micro instance in EC2 could serve this purpose.
推薦閱讀
- ETL with Azure Cookbook
- 反饋系統:多學科視角(原書第2版)
- Learning Apache Cassandra(Second Edition)
- Windows程序設計與架構
- RPA:流程自動化引領數字勞動力革命
- 大型數據庫管理系統技術、應用與實例分析:SQL Server 2005
- Implementing Oracle API Platform Cloud Service
- LMMS:A Complete Guide to Dance Music Production Beginner's Guide
- 強化學習
- Hands-On Business Intelligence with Qlik Sense
- Learn Microsoft Azure
- Data Analysis with R(Second Edition)
- Cloudera Hadoop大數據平臺實戰指南
- Hands-On Geospatial Analysis with R and QGIS
- 探索中國物聯網之路