Introducing Dragonfly Cloud! Learn More

Question: What is the difference between horizontal and vertical scaling in Redis?

Answer

Scaling is a crucial factor when you are dealing with any database system, including Redis. Scaling is divided into two main types: Horizontal Scaling and Vertical Scaling.

Vertical Scaling, also known as scaling up, involves adding more power to your existing machine. In the context of Redis, this could mean increasing the computational resources (like CPU, RAM) of the machine where Redis is installed. Vertical scaling allows for more storage and faster processing times. However, there's always a limit to how much power can be added to a single machine.

Example:

# Upgrading your server instance type to a one with higher CPU and RAM

On the other hand, Horizontal Scaling, also known as scaling out, involves adding more machines to your existing infrastructure, distributing the load evenly across these nodes. In the context of Redis, this refers to partitioning your data across multiple Redis instances. This approach is typically used when the data size grows beyond the capacity of a single machine or a single machine is not able to meet the read/write throughput.

Example:

# Sharding keys across multiple Redis instances # Let's say we have 3 Redis instances redis_nodes = ['redis://node1', 'redis://node2', 'redis://node3'] def get_redis_node(key): node_index = hash(key) % 3 return redis_nodes[node_index]

In terms of choosing between the two, it largely depends on your application needs. If you need to store more data and your current machine is unable to accommodate it, then vertical scaling could be a solution. But if your application demands more read/write operations that a single machine cannot handle, then horizontal scaling would be the way to go.

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

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.