Chapter 15. Configuring Sharding

In the previous chapter, you set up a “cluster” on one machine. This chapter covers how to set up a more realistic cluster and how each piece fits. In particular, you’ll learn:

  • How to set up config servers, shards, and mongos processes

  • How to add capacity to a cluster

  • How data is stored and distributed

When to Shard

Deciding when to shard is a balancing act. You generally do not want to shard too early because it adds operational complexity to your deployment and forces you to make design decisions that are difficult to change later. On the other hand, you do not want to wait too long to shard because it is difficult to shard an overloaded system without downtime.

In general, sharding is used to:

  • Increase available RAM

  • Increase available disk space

  • Reduce load on a server

  • Read or write data with greater throughput than a single mongod can handle

Thus, good monitoring is important to decide when sharding will be necessary. Carefully measure each of these metrics. Generally people speed toward one of these bottlenecks much faster than the others, so figure out which one your deployment will need to provision for first and make plans well in advance about when and how you plan to convert your replica set.

Starting the Servers

The first step in creating a cluster is to start up all of the processes required. As mentioned in the previous chapter, you need to set up the mongos and the shards. There’s also a third component, the config servers, which are an important ...

Get MongoDB: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.