Dragonfly Cloud is now available on the AWS Marketplace - Learn More

Question: How many nodes should be in a Redis cluster?

Answer

Redis Cluster is a distributed implementation of Redis with automatic partitioning across multiple Redis nodes. It provides high availability and can survive up to N/2-1 failures where N is the number of master nodes.

There's no hard limit to the number of nodes in a Redis Cluster, but there are practical considerations that affect your choice:

  1. Data Size: If you have a large amount of data, you'd need more nodes to store it all. Redis stores the entire dataset in memory, so the combined memory of all nodes must be sufficient for your needs.

  2. Read/Write Load: If you have heavy read/write operations, having more nodes would help distribute the load.

  3. Fault Tolerance: More nodes provide better fault tolerance. With 'n' master nodes, the cluster remains operational as long as the majority (n/2+1) nodes are operational. For example, if you have 3 master nodes, the cluster can survive 1 node failure; with 5 masters, it can survive 2 node failures, and so on.

  4. Performance Considerations: Each additional node adds some overhead for synchronization and communication within the cluster. So there's a trade-off between scalability and performance.

For most applications, it is typical to start with a minimum of six nodes (three masters and three slaves). The exact number would depend on your specific use case, capacity planning, and high-availability requirements.

Here's an example of creating a 6-node Redis cluster using redis-cli utility:

# Start Redis instances for port in {7000..7005}; do mkdir -p ./nodes/$port redis-server --port $port --cluster-enabled yes --cluster-config-file nodes.conf --dir ./nodes/$port & done # Wait for all instances to start # Form the cluster echo 'yes' | redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1

In the above example, --cluster-replicas 1 option is used to set one slave for each master node, ending up with a total of six nodes.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost