MongoDB supports horizontal scaling by the use of sharding. A sharded cluster consists of 3 parts:
- Configuration replica set to store metadata
- Shard replica set(s)
- Mongos server as a query router that uses metadata from config replica set to query data from the shard(s)
Every replica set can consist of primary and secondary instances. Single secondaries can also be replaced with arbiters if the budget is too low to have all these instances.
My sample under https://github.com/mbogner/mongo-cluster consists of a configuration replica set from a primary and two secondaries. Further it includes 2 shards that are also replica sets with a master and 2 secondaries. Of course it also includes a mongos server to use the cluster.
Note: Of course creating all these instance on a single machine with docker doesn’t make sense and you would need 10 servers to properly deploy that setup. This was just a test how to setup mongodb with shards and authentication and to play around with replacing nodes.