Imagine my Redis instance runs out of memory, so data becomes too large to hold in memory, or Redis becomes a bottleneck because it can no longer handle requests. In this case, how can I create a larger Redis database with more capacity and memory?
Clustering is one of the most appealing features of Redis. Redis can be used as a primary or master instance to read and write data, and to have multiple replica instances of that primary instance for reading data.
In this manner, you can extend Redis to accommodate more requests while also increasing the database's high availability, because if the master fails, one of the replicas can take over and your Redis database can continue to work normally. If the master fails, one of the replicas can take over and your Redis database can continue to function normally and handle more requests. In addition, you can increase the high availability of your database.
Imagine a scenario A single server cannot accommodate your dataset as it grows too big. Furthermore, we've slowed down the reads in the database, so all requests that basically query on data are now handled more efficiently. We still have only one master instance and this one has to handle all the writes.
So what is the solution here? Redis supports sharding as well, which is a concept common to database systems. As you can see, sharding is essentially taking a complete data set and breaking it up into smaller chunks, where each shard is responsible for storing a certain subset of data.
Alternatively, you can create 4 shards, each of which is responsible for reading and writing to a subset of the data, rather than having one master instance that handles all writes to the entire dataset. Furthermore, each shard only needs about a fourth of the memory, since they only have a quarter of the data. In essence, so you can scale your cluster horizontally, you can distribute the shards across smaller nodes: