Serverless: A Modern Infrastructure
Serverless computing is one of the newest growing movements in cloud computing and continues to increase its presence.
Join the DZone community and get the full member experience.Join For Free
What is Serverless?
When I heard "serverless" for the first time at a conference, I was taken aback. But gone are those traditional ways for hosting an application in a server that has to be:
1. Properly maintained
2. Continuously monitored
3. Upgraded and patched
These are always a pain point for developers and each of these requirements needs time and effort. Scaling in the traditional server is also a huge ask.
Serverless introduces a model which takes away the overhead of building and maintaining a server for your application. This model is only responsible for executing a piece of code by allocating resources according to execution requirements dependencies for the server. Hence, the name "serverless."
The Scene Before Serverless
In a traditional model, the application is deployed and the major role of server is to house data, retrieve it when needed, manage it, and serve requests. This can be considered as a safehouse of information and when requested by a secure channel it delivers after verification.
We can think of servers as a physical system that acts as a medium between many devices and a central database.
Traditional servers fulfill all the needs but it has its own drawbacks...
Costs for building the infrastructure.
A high rate of failures because of physical setup.
Efficiency and Effectiveness as the focus is diverse away from the core application.
Dependencies of experts for maintenance.
Agility and Flexibility with scaling and upgrading physical setup.
If we observe all these issues, we will notice it has a direct or indirect impact on the cost of a company.
Scene After Serverless
The fact is, we do need a server but we do not have to handle its dependencies anymore. We shift our entire focus on the application development and improvement, not on the infrastructure, to make it available. We leave it up to the experts in these fields and leverage their services to execute our application.
There are cloud giants (AWS, Azure, Google Cloud) who have their own huge infrastructures that can support our requirements of hosting our application. The service providers have the responsibility to make the application available and maintain the servers. They also look after for failures and mitigate them as well. That's a lot of relief for application providers both from maintaining infrastructure and also they pay as per the usage.
Isn't it a great model? With every model comes with advantages, drawbacks, confusion, and challenges, but before speculating we need to understand it in more details.
Serverless Explained In Depth
Technically, this is a stateless computational arrangement that takes in application code and waits for any events to execute the code. That is very simple. The only catch is to design the application code in such a way that this fits into this architecture. To resolve this, all the third0party serverless service providers provide us a way to design a function that contains the logic of the application and a trigger (HTTP Request, In-App Activity, etc.) that will invoke the function. This is otherwise known as Function-as-a-Service (FaaS).
The might vary based on the need of the application and the framework. Let me try to explain in a simple manner.
The events that invoke the Function for the core logic
HTTP Request from the web browser (Static HTML with JS Rest API)
Web Hooks Event (GIT Commit, S3 Data Upload, DB Triggers)
The function containing the core logic of the application which is hosted in a serverless third-party provider like AWS Lambda or Azure Functions.
After executing the function, it is either stored into data warehouse for analysis or it might be sent to other services as part of an ETL processor or might just interact with DB and send a response to the requestor.
Benefits of Serverless
Let's see some of the key benefits that serverless brings.
Write your application and begin using the service. No more deployment infrastructure.
This is one of the most important aspects of serverless as the payment is based on usage. The concept of pay-as-you-go is gaining much interest as it saves revenue when the services are not used. In the traditional model, we need to spend to keep the server up and running whether or not the services hosted are used. This also cut down the price for maintaining an infrastructure team for maintaining the servers on premises.
When you host your application on third party serverless providers they provide the option to choose resources depending on the need of the application. If your customer base increases then scale up; otherwise, scale down easily without having to risk much.
Efficiency and Productivity
Letting the experts deal with your hosting and making the application available for use, the application developer can entirely focus more on the application core logic and effectiveness.
Low Risk of Failure and High Availability
These service providers provide these services to many vendors so they always have a fall back mechanism in case of risk of failure. From a user perspective, customers will not see any outage as they can swiftly switch to back up servers instantly.
They have multi-location servers distributed on a global scale. No matter where you try to access the application, the latency would be low as the requests are served by the nearest data center of the providers.
Drawbacks of Serverless
Though we discussed some of the benefits of using serverless, sometimes there are drawbacks which affect the customers. So think carefully before choosing serverless.
This is still a niche in the market and so enhancements and improvements are continuously happening in these areas. As customization is still on and scope of improvement is still there it might be unstable.
In some scenarios, it has been proven that it can cost you more to use serverless rather than hosting it on your own.
There are different providers and the execution time varies from providers to provider. Also, the technology stack supports making it difficult to switch between providers when needed. Check the support that is provided by the providers before selecting one.
Troubleshooting is a killer, as the architecture encourages to provides the solution in smaller modules or function the challenge is to monitor and debugging.
Moving from a traditional way to a future-driven approach is not easy to adapt.
So far we have seen the benefits and drawbacks of serverless. We have seen the future and past models. But the decision always depends on the business and the forces driving the business.
Having said that, I do believe all the improvement happening in these areas and the amount of investment done by large players will lead to the future era of wider cloud and serverless adaptation. With more and more people adopting, it is going to improve every day.
Opinions expressed by DZone contributors are their own.