How to build scalable web applications
A scalable web application is called so because it can take more requests linearly in a more graceful manner. As more hardware is added, the website will be able to handle loads of requests at a single time. To say that a website has scalability in action is simply to mean that as users increase and requests overflow, the website will be able to handle them all equally well.
Example of a popular website that have been scaled successfully.
Looking at the growth of Facebook, it would be amazing to note how it has grown over the years. Even if you are not a regular Facebook user, it would be hard to ignore the impact the social media channel has over enterprises and businesses. According to a statistic, there are more than 1.94 billion active Facebook users for March 2017 , recording an increase of over 18% every year. As for daily mobile active users, the numbers are staggering at 1.15 billion users.
Facebook is written in PHP, and their massive success lies in its ability to scale to a million users, thanks to huge application architecture. The architecture avoids bottlenecks, making it scalable in any language. The shape of the curve (relating cost to usage) is what determines the application architecture. When an application is scalable, the curve will be more diagonal, but when confronted with bottlenecks, it would turn almost vertical.
The language, database or compiler used also pays an important roe in the shape of the nonlinear curve. If there is an underlying design flaw (more than the implementation detail), then the curve is key to shoot up fast. The ever evolving Facebook’s architecture is looked after by some of the best engineers in the industry. Facebook has its own version of optimised PHP and have developed totally new software like Apache Cassandra.
Now comes the million dollar question – How do you build scalable web applications?
Here are some simple options to scale your web applications:
1. Scaling up
Once the load on the back-end tires becomes too heavy to handle, it is not possible for the website to function. A feasible, but probably a mighty expensive option would be to scale up the resources on a per-entity basis. Scale this on other dimensions like network speed, IOPs, storage capacity and memory as well. The reason why this becomes expensive is because it doesn’t offer a built-in elasticity, so this could turn costly when the load is low.
However, it is important to note that scaling out architecture needs a load balancer (requests from end users, boundary between external and international networks.) so it can stream connections of a particular type and scanning group (for tracking system load, spawn new CPU instances and track active instances inventory).
The need for scaling has led to the demand and deployment for large scale scaling. Caching can improve performance and reduce resource consumption. Resource usages includes CPU, S3 fees, data store fees, external API usage and database. To ensure where caching can be applied, perform a data analysis to help you understand request distributions and data sizes, including the read-write ratio.
3. The type of partitions to be done
The purpose of scaling is of course to add capacity. This can be done in two ways – vertical or horizontal. In vertical scaling, you add more resources, for example, larger or harder drives to a singe server. The compute operation is bigger, with better memory and speedier CPU. In vertical scaling, you take a singe resource and increase the handling capacity. In horizontal scaling, you can add more nodes. The most common way to do horizontal scaling is by breaking up services into partitions or shards. These shards would be assigned to cater to specific functionalities (for example, catering to the interests of different kinds of users). The benefit of shards is that it can provide stores of added capacity. However, the catch here is that your initial design must have provision for horizontal scaling, because adding this later might be a really difficult task.
Things to remember while scaling applications, Note these points while on the task
1. No compromises on website up-time
The website should be available to users at a times. Imagine running an e-commence store and then having the server going down each time there is a spike in request. So website up-time is very important, and scale your web application so it would be available all the time, irrespective of system failures and interruptions.
2. Retrieval option
Users may come back to view the same data, so they should have ready access to the sane. Unless of course, you have the data updated. You can gain trust from the users if they know they can gain access to website data any time they want it.
The main aim of scaling the application is to ensure excellent performance. Quick response with instant retrieval followed by low latency is extremely important.
After scaling the website, it is very important to check for manageability of the website so it becomes easy to operate, maintain and update.
There is a misconception that PHP is not scalable. How then would other high-scale sites PHP run? Scalability is more about application architecture, rather than just language. The time required to develop scalable web applications depends on the complexity of the application and the framework used. There are two different programming layers in a scalable app: Front end and Back end. As the name suggests, Front end is something the user interacts with and the interface could be anything from Android to iOS. The back end consists of about 80% of the total work, but the user is not aware of this part of his web application. Functionality plays a major role in scalability. A user might want to load images, so storage scalability has to be considered because he might need to retrieve it at any time. For better image downloads and requests, low latency is very important.
Here some interesting reads regarding this topic:
7 Stages of scaling web applications, Strategies for architects.
How to build scalable web applications?
Building scalable applications on google cloud platform.
Flickr.com/ klarititemplateshop.com/ Blogtrepreneur
About the author: Deepak is Head of PHPBabu and also works at the parent company YUHIRO Technologies Private Limited as office manager.