Horizontal and Vertical Scaling
Being a software engineer, you would have designed a website or application and deployed it on any server. Imagine that the developed application starts getting popular, and many users engage with it daily. Everything seems perfect, but as the traffic increases, you realize that the server or machine you used while designing your system would no longer be able to handle all these requests and may stop responding anytime; hence the application would crash. At such times you need to do something to increase the scale of your system to handle such enormous requests at once.
To expand the scale, you need to upgrade your system's current configuration or add additional hardware devices. This process is known as Scaling.
Any developer working for any firm or organization may encounter this situation and would be expected to find an optimal solution for the same; therefore, many questions on the concept of Scaling are commonly asked in various technical interviews.
The Process of Scaling the database in your system can be done by using any one of the two approaches, namely:
- Vertical Scaling
- Horizontal Scaling
Let us now discuss the concept, advantages and disadvantages of both types of scaling individually:
Vertical Scaling
It is commonly known as the 'scale-up' approach. The concept of Vertical Scaling deals with upgrading the same machine or moving to a newer machine with higher specifications so that it would now be able to handle the increased traffic on the website or application. One can update their devices by embedding some additional RAM storage or adding some other features to enhance the overall performance of your application.
In simpler terms, Vertical Scaling can be done easily by switching the servers with the better versions.
Even though this approach needs not manipulate the code, it has several drawbacks.
Let us discuss some more critical points of this approach
- Does not need to manipulate the code or partition the database as the ability of the existing single node to handle the traffic is increased.
- Implementation is easier.
- Lesser requirements for the workforce, as only one system, is managed.
- Since there is no change in the hardware, Compatibility remains undisturbed.
- The Vertical Scaling approach is commonly preferred by Small to mid-size firms or organizations.
- Example: MySQL and Amazon RDS.
Limitations of Vertical Scaling
- Reduces the possibility of improving the network or disk input and outputs.
- The extent of Scaling is limited.
- Replacement of the machine or server takes time and creates a halt in the working of your system.
- Vertical Scaling increases the risk of hardware failure.
- The complete procedure is expensive.
- Upgrading the system after vertical scaling is complicated.
Horizontal Scaling
Horizontal Scaling is also known as the 'Scale-out' approach. This is the widely used approach for systems with higher requirements for being highly available or failover. In the technique of Horizontal Scaling, we upgrade the system by parallel adding more machines or servers. This helps to divide the workload of processing or storage across multiple devices, enhancing the whole system's performance. In this approach, we directly add more instances of the machines with a similar configuration to the existing pool or network of the servers. The current server configuration remains unchanged. Also, unlike the vertical Scaling, this does not stop the working of our system while we add the new servers. The Horizontal Scaling approach is quite famous among various organizations as this technique increases the input-output concurrency, as well as the load at each existing node, is reduced. Horizontal Scaling also increases the disk capacity of the system as there are comparatively more systems.
Let us look at some of the key points of this approach,
- The horizontal Scalability of a system can be easily acquired by implementing the distributed file system, clustering and load-balancing.
- The User Traffic on the system can be effectively managed using this approach.
- In this approach, the Fault Tolerance of the system can be easily checked.
- Upgradation is simple.
- No downtime while adding the machine or server hence continuous and instant availability.
- Increasing or reducing the size per the system's needs is more effortless.
- Overall implementation is cheaper as compared to the 'Scale-up' approach.
- Large IT companies like Google, Yahoo, eBay, Amazon, etc., prefer Horizontal Scaling.
- Example: Cassandra and MongoDB.
Limitations of Horizontal Scaling
- Designing an architecture model for implementing Horizontal Scaling in a system is a complicated task.
- Licensing Fees are high.
- Cooling expenses and electricity bills are expensive as multiple machines are used
- Integrating various devices into a single network requires different switches and routers.
Differences between Horizontal Scaling and Vertical Scaling
As we understand the basic principle behind both these approaches now, let us look at some of the fundamental differences between them.
Terms | Horizontal Scaling | Vertical Scaling |
Load Balancing | Horizontal Scaling needs load balancing to manage and divide the data across all the connected servers in your system. | While in the vertical Scaling approach, there is only one machine to handle the total traffic, so no load balancers are required. |
Failure Resilience | Horizontal Scaling is more immune to system failure, as with several machines, if any of them crashes for some reason; the other servers in the network handle the user traffic and prevent the system failure. | In Vertical Scaling, there is only one machine: the single point of the crash, and hence it is much more prone to System failure. In simple words, availability in the vertical approach is higher than in the vertical scaling approach as the database runs on a single machine. When it crashes, the complete system fails. |
Machine Communication | The horizontal Scaling approach uses a network of various servers or machines with distributed data and user traffic. Hence it requires network communication, and the calls over the network are time-consuming and are prone to failure. | While in vertical Scaling, the transmission over a network does not exist as there is only one machine, and it works on the inter-process communication, which is comparatively much faster. |
Data Consistency | In the Horizontal Scalingapproach, total requests are divided across various systems. Different servers deal with different demands and handle or store additional data at different locations; hence, syncing the complete data together is impossible. | In vertical Scaling, all the requests are handled by a single machine and all the data is stored in the same place, so inconsistency does not occur. |
Drawbacks or Limitations
According to your budget or space, you can add as many machines as you need at a particular time in the horizontal scaling approach to scale up the complete system, but this is not the case in the vertical scaling approach; there is a limit for upgrading the machine. After reaching the limit, there is no way to increase it without further downtime.
Choosing the Approach for Your Application
Until now, we have seen the basic idea behind the implementation of approaches, their pros and cons and some of the fundamental differences between them. The main problem arises when the developer decides which method is best suited for their application or system. This is a tricky task and confusing too. The developer must take an intelligent decision here. Firstly, you should get a complete blueprint of your application's present and future requirements, as well as focus on the goals for the system and keep in mind where you would wish to add value. This critical decision should only be taken after focusing on these factors:
- Performance characteristics and requirements.
- Required Response Time.
- Expected requirement for system availability.
- Degree of Fault tolerance of your system.
- Reliability level of the design.
- Clear Understanding of both the approaches
- Level of data consistency needed.
- Throughput of your application.
- Short and Long-term Scalability Goals.
All of these factors would help you better understand your system's requirements and business goals. Apart from your choice, you should check whether the upgraded model would be compatible with your needs. You can choose a vertical or horizontal approach per your needs or even both in any cloud environment to enhance the performance of your application.
A common question is which of these approaches is usually used by large tech companies. The answer to this is 'Both'. The experienced teams at such companies use their excellent qualities and follow the hybrid approach to combine the speed and consistency of vertical scaling with crash resistance and infinite scalability property of Horizontal Scaling.
Keeping in mind the requirements and all these points, you can design a suitable model for your system.