SYSTEM DESIGN: HORIZONTAL VS VERTICAL SCALING
By: Silvia Spolaore
Tags: Vertical Scaling, Scalability, System Design, Horizontal Scale, Scaling

HORIZONTAL SCALABILITY

With horizontal scalability we add machines to our pool, so instead of one expensive server we can have a bunch of cheaper server. Applications designed to support horizontal scalability are typically more flexible and can handle capacity increases very well. For instance, if a server is reaching its maximum capacity, it is possible to add another server and split the workload across the two servers.

Advantages of scaling out:

It scales well : increase or reduce the number of servers quickly.

: increase or reduce the number of servers quickly. Resilient to failures : When one server goes down, others are available to handle requests.

: When one server goes down, others are available to handle requests. Load balancing: client requests are distributed across multiple servers, it ensures that no server is overloaded.

Drawbacks:

Data are inconsistent : Data are stored across several nodes, so they are not consistent instantly.

: Data are stored across several nodes, so they are not consistent instantly. High load network: communication between servers will be over the network through remote procedure calls and it is slow.

LOAD BALANCING

As we have seen before, scaling out needs load balancing in order to forward the requests to the servers. Reliability and high availability are maintained by redirecting the requests only to servers which are available. If there are servers offline, those ones will be removed from the load balancing setup.

There are different algorithms for load balancing:

Round Robin: it has the list of server and it forwards the request to each server in turn. If we have 3 servers, the first request goes to the first server, the second one to the second server and the third one to the last server.

When it reaches the end of the list, the load balancer goes down to the list again. Round Robin requires that all the servers are the same (same capacity, same load, same storage) and if not, the workload distribution couldn’t be efficient. In fact, if we have a server with lower capacity than another one, it could be overloaded. To overcome this problem, we can use Weighted Round Robin Load Balance algorithm where we assign a weight to each server. Server with higher weight will receive more client requests.

When it reaches the end of the list, the load balancer goes down to the list again. Round Robin requires that all the servers are the same (same capacity, same load, same storage) and if not, the workload distribution couldn’t be efficient. In fact, if we have a server with lower capacity than another one, it could be overloaded. To overcome this problem, we can use Weighted Round Robin Load Balance algorithm where we assign a weight to each server. Server with higher weight will receive more client requests. Least Connections: this algorithm forwards the request to the server that is processing the least number of requests. In order to do this, the load balancer needs to find which server is the least busy so it might need to do additional computing that may take a while.

IP HASH: the request is sent to the server based on the Client IP. IP Hash ensures that requests from a particular client are always directed to the same server, as long as it is available. The issue we could have is that a server becomes overloaded, so to avoid this, we can set capacity rules for the number of connections on a single server from a single source, or on how many connections from a single source are allowed.

WHICH ONE IS BETTER TO USE?

It depends on the requirements and needs but I would say both. We could have a hybrid solution where we scale horizontally and each machine is fast and has a lot of power.

Otherwise it is possible to start scaling vertically and then, if we need to handle a lot of traffic, we can switch to horizontal scaling.