In traditional web hosting, the hosting charge increases as the site or application traffic increases. Hosting companies take two variables into account - page traffic & the computing power needed. Most of the time when the site is content-driven, users are just reading the content. Only a small portion of users provide feedback by comments or in other forms that consume bandwidth of the server. So, we might not need the same level of increase in computing power compared to the increase in traffic.
But if we are using an enterprise application like Drupal, where traditional deployment architecture is used, we might require additional computing power as the traffic increases. Since hosting companies keep their pricing based on the number of page views or number of hits received by server or computing power (CPU+RAM) required to serve the traffic, hosting cost increases proportionally. In the case of one of our clients, the charges increased from $100 to $1,000 per month within a year, and it could again go up further. This puts a substantial financial burden on firms where revenue is not a direct function of page traffic.
Where to use AWS Lambda in Serverless Architecture
Consider the example where the users upload a video file into your Drupal site and the system creates a thumbnail for preview purpose. But many times, users log in to the site just to browse. So, it is a wastage of resources to keep your web server like apache waiting for the trigger event to happen so that it can execute the response action.
AWS Lambda is a solution to overcome this challenge. In this method, the code for executing the action, like creating the preview, is kept in a file. It is executed only when a trigger event happens, like the uploading of the video. Billing is only for the resources the program uses and the time taken. In effect, the server is nonexistent until the user needs it and hence it is called serverless computing or FaaS, function as a service.
Server tasks can be divided into smaller functions. Only a few of these functions need to execute code blocks. Lambda is a service that allows you to execute code without the need to manage servers. Lambda takes care of running code as a response to triggers like events, Http requests, or API calls.
It manages the varying computing capabilities needed for different functions, and the number of users using the function resulting in smooth scalability. When we implement lambda in a Drupal site, it helps us in faster and efficient execution of functionalities like localization, personalization and content processing, etc.
Using AWS Lambda functions, we have seen a reduction in server cost by up to 70% without any compromise on performance.
Basic implementation process to deploy Drupal with AWS Lambda
- We hosted the client’s Drupal website on an Elastic Load Balancer(ELB)
- All the static assets were uploaded into a S3 bucket, instead of serving from drupal origin itself. S3 is the low-cost file storage service which can significantly reduce the EC2 storage size.
- Implemented a CloudFront distribution along with multiple lambda functions to distribute our dynamic and static content.
- Then the CloudFront interacts with the end-users for data exchange.
From Monolith to Serverless microservices
Benefits of Serverless architecture
- Lower costs - Compared to traditional hosting, serverless saves the cost for the user as he doesn't have to pay for unused CPU time
- Simplified scalability - There is no need to set elaborate policies for scaling in serverless, as scaling can be handled on-demand.
- Simplified backend code - In FaaS, we can create separate functions for specific tasks like making an API call.
- Quicker turnaround - The time to market is much lower for serverless architecture due to the simpler deployment process to introduce new features and bug fixes.
The Challenges
We learned that serverless architecture can help us scaling without increasing the cost proportionately. But we should be aware of certain challenges in comparison to other Pass platforms we have been using, where the only thing we have to worry about is building our applications. A few points we need to keep in mind are -
- The technical team should be self-sufficient to handle the troubleshooting and security aspects of the application
- We need to build our own deployment system, along with CI-CD tool to track and update multiple functions
Going Forward
Serverless architecture helps in increasing efficiency by using the principles of lean management and modularity. It is not a magic wand that will solve all your issues, but it puts your business in a better position to take advantage of technology. In the coming years, we can expect a lot of advancements in this field. The serverless architecture will witness wider adoption, due to the benefits of cost savings and scalability.
Get in touch with us if you would like to know more about how your business can implement and benefit from Serverless & Cloud technology.