![](bg6.png)
cluster. Using the sharding based on a hash function,
the resharding is automatically performed by the sys-
tem.
In MongoDB, the sharding is assigned to the col-
lections, which means that each collection can have
different sharding settings. In contrast, Redis can use
an automatic sharding solution on the whole database,
so the database administrator has not so much oppor-
tunity to influence the sharing in a way.
6.3 Combination of Sharding and
Master-Slave Replication in
MongoDB and Redis
To build the combination of sharding and master-
slave replication in Redis at least 6 nodes are needed,
3 for the sharding, and every shard should have its
own replication. Considering the same problem of
MongoDB, it needs at least 7 nodes, namely mongos
(router), config servers (with replication 2 nodes), for
the sharding 2 nodes, and each shard node has its own
replication.
With this cluster type, both databases support the
dynamic horizontal scale, namely new nodes can be
added to the cluster even when the system work.
In this environment, it is not easy for Redis to
support the multi-level master-slave replication, since
the built system makes the decisions about who is
the masters and the slaves in the cluster and not the
database administrator (as in the case of the master-
slave replication). However, each node can have ad-
ditional slaves, since the slave is configured to be a
slave. MongoDB does still not support multilevel
master-slave replication.
The rest point of views are similar to the sharding
or the master-slave replication. The client knows all
the nodes of the cluster in the case of Redis, mean-
while, in the case of MongoDB, the client connects to
one of the mongos (routers). Both databases can use
a hash function to shard the keys, but MongoDB has
a range shard solution, too. The default synchroniza-
tion is asynchronous in both cases, and in both cases,
the synchronous write can be achieved. And finally,
Redis can add shard settings for the whole database
only, meanwhile, MongoDB can granulate the shar-
ing to collections.
7 CONCLUSION
In this paper, the distribution models of NoSQL
database management systems were introduced, high-
lighting the master-slave replication, the sharding,
and their combinations. The real solutions were in-
troduced on two NoSQL databases: MongoDB and
Redis. They are not in the same NoSQL categories,
but both of them realize the sharding and master-slave
distribution models and their combinations. And they
do not realize the peer-to-peer replication.
Finally, we compared the distribution models of
the two NoSQL databases. We found that there is
no big difference between the two realizations, but of
course, they are not the same. The main difference is
that MongoDB needs additional nodes to realize the
sharding, namely, it uses config servers and the mon-
gos as a router, but it is enough of two nodes to store
the shards. At the same time, the Redis needs 3 nodes
to realize sharding. Both of them can use a hash func-
tion to shard the data, but MongoDB has another so-
lution to this question. Both of them have a solution
to store two different shards on the same node. Both
of them support horizontal scalability with sharding.
By default, both of them use asynchronous replica-
tion, but both of them have solutions to realize syn-
chronous replication.
Altogether we found that it is easy to build the
clusters with both NoSQL databases. We can state
that the distribution models of MongoDB are more
complex than the distribution model of Redis. In this
way, it is easier to build a Redis cluster as a MongoDB
cluster. All in all, the application to be developed will
show which database management system should be
chosen.
REFERENCES
(2023a). DB-Engines Ranking. https://db-engines.com/en/
ranking.
(2023b). MongoDB documetation. https://www.mongodb.
com/docs/manual/tutorial/getting-started/.
(2023c). Redis Documentation. https://redis.io.
Banker, K., Bakkum, P., Verch, S., Garrett, D., and
Hawkins, T. (2016). MongoDB in action. Manning,
Shelter Island, NY, second edition.
Carlson, J. L. and Sanfilippo, S. (2013). Redis in action.
Manning, Shelter Island, NY.
Cattell, R. (2011). Scalable SQL and NoSQL data stores.
ACM SIGMOD Record, 39.
Corbellini, A., Mateos, C., Zunino, A., Godoy, D., and
Schiaffino, S. (2017). Persisting big-data: The
NoSQL landscape. Information Systems, 63.
Davoudian, A., Chen, L., and Liu, M. (2018). A Survey on
NoSQL Stores. ACM Computing Surveys, 51.
Diogo, M., Cabral, B., and Bernardino, J. (2019). Consis-
tency Models of NoSQL Databases. Future Internet,
11.
Gajendran, S. (2012). A survey on nosql databases.
Sharding and Master-Slave Replication of NoSQL Databases: Comparison of MongoDB and Redis
581