What are horizontal and vertical scaling? And when do you use them?
Vertical scaling is adding oomph to the machine that an application is running on. Perhaps your e-commerce site is getting more traffic as your business grows, and it’s starting to creak at the seams. A common way to give the application a boost, is to add more RAM, more processors, more bandwidth, or more storage to your machine. Maybe you simply move your application to a new, more powerful machine.
Using vertical scaling is great for applications that can only run on a single machine. Perhaps you are using an off the shelf web shop that is fully integrated and can’t run on more than one machine at a time. Or perhaps the server you are using is underpowered for the latest version of the software you have installed.
Vertical scaling can be a quick and easy way to get your application’s level of service back up to standard. On the negative side, vertical scaling will only get you so far. Upgrading a single server beyond a certain level can become very expensive. If you already have a quad processor, moving up to eight processors can add cost quickly. And if you already have eight processors, you may start to wonder if there is an easier way. Especially if your disaster recovery strategy is to have a mirror machine at the ready at all times!
Horizontal scaling, on the other hand, is adding more servers to your application to spread the load. The simplest case of horizontal scaling may be to move your database onto a separate machine from your web server. Now your web server can simply satisfy requests, and your database server can simply crunch data.
If your application can be broken down into more modules, perhaps it has a three tier architecture – a database layer, a business logic layer and a presentation layer – then it can be spread across more servers. If your application is running on three machines and you find your database is holding you back, you can add a second machine to your database layer. Your data crunching capacity is virtually doubled. If your presentation layer is the next to slow you down, you can simply add a second machine serving web requests and split the traffic with a load balancer.
Horizontal scaling can only be applied to applications built in layers that can run on separate machines. Horizontal scaling applies really well to on-demand cloud server architectures, such as Amazon’s EC2 hosting platform. Horizontal scaling can also facilitate redundancy – having each layer running on multiple servers means that if any single machine fails, your application keeps running.
An application that has been designed from the ground up to be scaled horizontally tends to be really easy to scale down too. If you have a seasonal demand pattern, it is very easy to bring your application layers back down to run on a single server when demand is low. And you can add the servers back when demand is high again. And best of all? A horizontally scalable application tends to run on low end hardware. You tend to add low power servers into your cluster to reduce load, rather than needing powerful (and more expensive) machines to run your application.
So which scaling strategy should you use? Both are useful. There are many applications that can only scale vertically. They can only be run on a single server. You have a clear strategy choice with these applications! But, a well written application should scale horizontally very easily. An application that is designed to scale horizontally can also be scaled vertically. So you still have a choice. You can weigh up the cost of vertically scaling with an extra 4Gb of RAM vs horizontally by adding a new server in your cluster.
At Singing Horse Studio LLP, we always write our web applications with horizontal scaling in mind. It’s easy to do, it gives you the maximum choice in the future, and it tends to drive flexibility and modularity into your web application. And those things are almost never bad .