In this set of scenarios we will explore the dif­fer­ence between MongoDB sharding and repli­ca­tion, and explain when each is the most ap­pro­pri­ate solution. Both repli­ca­tion and sharding are forms of hor­i­zon­tal scaling to create a high avail­abil­i­ty (HA) setup.

Both repli­ca­tion and sharding can be used (in­di­vid­u­al­ly or together) for hor­i­zon­tal scaling of a MongoDB in­stal­la­tion.

Sharding

Sharding is MongoDB's solution for meeting the demands of data growth. Sharding stores data records across multiple servers to provide faster through­put on read and write queries, par­tic­u­lar­ly for very large data sets.

Any of the servers in the sharded cluster can respond to a read or write operation, which greatly speeds up query responses.

Be secure. Buy an SSL cer­tifi­cate.
  • Secures data transfers
  • Avoids browser warnings
  • Improves your Google ranking

Repli­ca­tion

Repli­ca­tion is MongoDB's solution for providing stability, backup, and disaster recovery to a MongoDB in­stal­la­tion. This process copies and syn­chro­nizes the replica data set across multiple servers. This prevents downtime if one server goes offline.

Any of the secondary servers can respond to read queries, but only the primary server will perform write op­er­a­tions. The results of the write operation will then be prop­a­gat­ed out to the secondary servers.

Scenario 1: Fault-Tolerance

In this scenario, the user is storing billing data in a MongoDB in­stal­la­tion. This data is mission-critical to the user's business, and needs to be available 24/7, even if a server crashes or is taken offline.

MongoDB repli­ca­tion is the best solution for this user. With repli­ca­tion, the entire data set is mirrored on multiple servers. If a server fails or is taken offline, the other servers in the cluster take over.

Scenario 2: High Per­for­mance

In this scenario, the user is running a social net­work­ing site which is run from a MongoDB database. As the social network grows, the MongoDB data set has grown along with it. The user is seeing query times and page loads increase beyond an ac­cept­able point. It is critical that the user's MongoDB in­stal­la­tion receives a major per­for­mance boost.

Setting up a sharded MongoDB cluster is the best solution for this user. The sharded cluster will break up the user's data set and store parts of it on separate secondary servers. Each secondary server can respond to read or write queries on its portion of the data, which greatly increases the in­stal­la­tion's response time.

Tip: Managed MongoDB from IONOS

Managed MongoDB from IONOS enables you to con­cen­trate on the es­sen­tials. From in­stal­la­tion to operation and main­te­nance work, IONOS makes sure you always get the best per­for­mance from your data banks.

Go to Main Menu